Forum Topic: Ioerrorevent Handling As3

(178 views • 7 replies)

This topic is 1 page long.

<< < > >>
None

Blaze

Reply To Post Reply & Quote

Posted at: 3/30/09 03:09 AM

Blaze LIGHT LEVEL 22

Sign-Up: 08/04/05

Posts: 6,989

Greetings,

So I have a scrollPane component, and I'm constantly loading a big number of files to it, so I need to check wheter this file exists or not, obviously if the file is not found, flash throws a IOErrorEvent exception, which I've tried to handle via catch method to no good. This is what I've been doing;

var req:URLRequest = new URLRequest(r);
try
{
holder.load(r);
}
catch(error:IOErrorEvent)
{
trace("lolerror");
}

And it doesn't catch it (also tried looking for error:Error type of exceptions). As far as I know, try and catch are only for synchronous errors, and IOErrorEvent seemed to be asynchronous, so I tried a different approach:

var req:URLRequest = new URLRequest(r);
function ioerror(err:IOErrorEvent)
{
trace("lolerror");
}
holder.addEventListener(IOErrorEvent.IO_ERROR,ioerror);
holder.load(r);

But still with no success. Perhaps it's not the component itself to what I have to add the listener? I've tried adding it to the "content" property, but as I thought it was useless.

Please keep in mind this is a scrollPane component, AS3.

Thanks in advance.


Happy

mike

Reply To Post Reply & Quote

Posted at: 3/30/09 03:49 AM

mike NEUTRAL LEVEL 20

Sign-Up: 02/24/00

Posts: 382

Exception handling in AS3 kind of sucks. :) You're right, asynchronous events like IOErrors won't get handled by try/catch blocks. I think the problem with your event listener is that you need to add it to holder.contentLoaderInfo (which is the object that throws the event), not loader itself.

!


None

Blaze

Reply To Post Reply & Quote

Posted at: 3/30/09 03:52 AM

Blaze LIGHT LEVEL 22

Sign-Up: 08/04/05

Posts: 6,989

At 3/30/09 03:49 AM, mike wrote: Exception handling in AS3 kind of sucks. :) You're right, asynchronous events like IOErrors won't get handled by try/catch blocks. I think the problem with your event listener is that you need to add it to holder.contentLoaderInfo (which is the object that throws the event), not loader itself.

My object is a scrollPane, not a Loader itself D: Therefore it doesn't have that object.

Altough If all else fails, i'll just load it with a Loader and then transfer the content to the scrollPane :(

Thanks!


None

mike

Reply To Post Reply & Quote

Posted at: 3/30/09 04:06 AM

mike NEUTRAL LEVEL 20

Sign-Up: 02/24/00

Posts: 382

According to the docs, the ScrollPane itself should trigger the IO error event, so the code you posted should work. I just made a quick test with a ScrollPane, and the event handler seemed to catch everything okay. Are you sure you are adding the listener to every scroll pane you have?

!


None

Blaze

Reply To Post Reply & Quote

Posted at: 3/30/09 04:11 AM

Blaze LIGHT LEVEL 22

Sign-Up: 08/04/05

Posts: 6,989

At 3/30/09 04:06 AM, mike wrote: According to the docs, the ScrollPane itself should trigger the IO error event, so the code you posted should work. I just made a quick test with a ScrollPane, and the event handler seemed to catch everything okay. Are you sure you are adding the listener to every scroll pane you have?

I only have one scrollPane, and this is the exact code:

function ioerror(er:Error)
{
	trace("ERROR!");
	/*var asdf:Array=new Array();
	asdf=r.split(".",2);
	trace(asdf[0]);*/
}
plano_holder.addEventListener(IOErrorEvent.IO_ERROR,ioerror);

var req:URLRequest=new URLRequest(r);
plano_holder.load(req);

tried the loaderInfo property too, but no luck . D:


Muted

mike

Reply To Post Reply & Quote

Posted at: 3/30/09 04:14 AM

mike NEUTRAL LEVEL 20

Sign-Up: 02/24/00

Posts: 382

I just made a blank SWF and pasted that code in. I had to changeer:Error to er:IOErrorEvent, but then it worked and I saw the "ERROR!" in the trace window. (I'm using Flash CS4, if that makes any difference!)

!


None

Blaze

Reply To Post Reply & Quote

Posted at: 3/30/09 04:17 AM

Blaze LIGHT LEVEL 22

Sign-Up: 08/04/05

Posts: 6,989

At 3/30/09 04:14 AM, mike wrote: I just made a blank SWF and pasted that code in. I had to changeer:Error to er:IOErrorEvent, but then it worked and I saw the "ERROR!" in the trace window. (I'm using Flash CS4, if that makes any difference!)

Actually I just made a whole new file, with the exact same code and won't handle the error, changed er:IOErrorEvent aswell, and no luck.

I doubt it's a fix done in CS4... I'm using CS3.

Thanks!


None

Blaze

Reply To Post Reply & Quote

Posted at: 3/30/09 04:30 AM

Blaze LIGHT LEVEL 22

Sign-Up: 08/04/05

Posts: 6,989

Problem solved, used a Loader and then set the scrollPane's source to the loader's content.

Not the most efficient way I know, but at least I'm not loading the content twice.

Thanks. :)


All times are Eastern Standard Time (GMT -5) | Current Time: 11:45 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!