Catching an IO Error Event in Actionscript 3
Posted on 2011-03-14
I'm writing an application is Flash CS5 using Actionscript 3.0. I'm trying to incorporate try and catch statements to catch an IO error if the loader cannot load an external SWF. (At the moment the program just stops if it encounters an error).
However the try, catch statements are not catching the error. Here's a bit of example code:
var swfLoader:Loader = new Loader();
var myUrl:URLRequest = new URLRequest(“Invalid file name.swf”);
now do some other stuff;
trace(“I’ve done the other stuff”);
trace(“Yoo Hoo! An IO error has been caught”);
When I compile the program it will run through and output "I've done the other stuff" and then stop. I never get my "Yoo Hoo!" error message. The compiler will then give me its unhandled IO error message. So the catch statement is not catching the error.
I then read that this type of IO error is called an asynchronous error, and must be handled by adding an event listener to the swfLoader. Thus:
trace("Error caught: "+event.type);
I've tried this but it doesn't catch the error either.
Can anyone point me in the right direction?