How to handle Unhandled IOErrorEvent

How to handle \ catch this error

Unhandled IOErrorEvent:. text=Error #2124: Loaded file is an unknown type.

I am trying to load a damaged image into MovieClip with AS3. I tried to use try and catch, but could not. I ask to add addEventListener

loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);

but he will not catch this mistake

Any help ?!

+3
source share
1 answer

If you want to catch any invisible errors, you can use the standard try-catch block.

var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener("complete", ldrDone);
ldr.contentLoaderInfo.addEventListener("ioError", ldrError);
ldr.load(new URLRequest("FILE-NAME-COMES-HERE"));

function ldrDone(evt:*):void
{
    //if the file can be loaded into a Loader object, this part runs
    var temp:*;

    try
    {
        temp = evt.target.content;
        //add it to the stage
        stage.addChild(temp);

        //this traces whether the loaded content is a Bitmap (jpg, gif, png) or a MovieClip (swf)
        var classOfObject:String = flash.utils.getQualifiedClassName(temp);
        trace(classOfObject);
    }
    catch(error:*)
    {
        trace("some error was caught, for example swf is AS2, or whatever, like Error #2180");
    }
}

function ldrError(evt:*):void
{
    //if the file can't be loaded into a Loader object, this part runs
    trace("this is the error part, Error #2124 won't show up");
}

This catches errors, for example, the swf you are trying to download is the old swf (published with AS2) - Error # 2180.

If the file cannot be found or does not look like any downloadable format, then the ioError operation is performed - Error # 2124.

+6
source

All Articles