Catching an unhandled IOErrorEvent in Flash AS3

Error #2044: Unhandled IOErrorEvent:. text=Error #2036: Load Never Completed.

That's what I see every time I try to load an image that doesn't exist using a Loader. I'm getting a list of URLs and can't validate if they're pointing to anything useful. Whenever it encounters a 404 it gives me that error.

I have tried to catch the error with every available IOErrorEvent there is (there are 7 of them),but none of them seem to capture the 404. Is there some other network event that I can be looking for to catch this condition?! I feel like I'm missing something obvious.

What I'd really like is to be able to catch the event regardless of its description and just deal with it... sort of like

myLoader.addEventListener(IOErrorEvent.*, dealWithError);

But that's illegal. I even tried catching


but that never calls back because, I guess, it gets the HTTP status after it deals with the error events, so, as it fails on the "unhandled" error event, it just gets lost. Are there events that aren't in the IDE that I'm overlooking?

All help appreciated.


if you are using a loader; try adding the eventListener to the contentLoaderInfo of the loader, e.g.

myLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loaderIOErrorHandler);

You must listen for the IOErrorEvent.IO_ERROR of your URLLoader object.

urlLoader.addEventListener(IOErrorEvent.IO_ERROR, loaderIOErrorHandler);
function loaderIOErrorHandler(errorEvent:IOErrorEvent):void{
    trace("ioErrorHandler: " + errorEvent);

If you trace the event object, then it should give you some information about what is going on.

It looks like IOErrorEvent.IO_ERROR should work. Also make sure you're using a URLLoader to retrieve the image.

Based on the example from the comments:

package {

    import flash.display.Sprite;
    import flash.utils.ByteArray;
    import flash.display.Loader;
    import flash.geom.Rectangle;

    public class Main extends Sprite {

        private var urlLoader:URLLoader = new URLLoader();

        public function Main() {
            urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
            urlLoader.load(new URLRequest(""));

           urlLoader.addEventListener(Event.COMPLETE, completeHandler);
           urlloader.addEventListener(IOErrorEvent.IO_ERROR, imageNotFound);

       private function completeHandler(event:Event):void {
           var loader:Loader = new Loader();

       private function imageNotFound(ev:Event):void{
        trace("File not found.");

Have you tried

loader.addEventListener(IOErrorEvent.IO_ERROR, errorHandlerIOErrorEvent);

[EDIT] Also include contentLoaderInfo events?

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler );

Need Your Help

"CA2000: Dispose object before losing scope" building Unity container

c# code-analysis fxcop static-code-analysis

I am using following code where I am getting fxCop voilation CA2000: Dispose object before losing scope:

DateTime.TryParse fails for one user

c# datetime

I need to parse dates in my program, but it fails on the machine of one user (in denmark). It works for his colleagues who all has the same settings as far as I can tell.