March 18, 2009

Unable to Catch IOErrorEvent’s when Loading a ByteArray into an Image

Filed under: ActionScript, Bug Fixes, Flex — Anthony @ 1:07 pm

I was trying to load a byteArray into an image control today and would randomly get an Unhandled IOErrorEvent message. Now this shouldn't really happen as the image control uses a default broken image icon to display when there are any loading problems. Well after trying to catch the error unsuccessfully I wanted to know what was going on.
So i went digging and i found in the base class of image, SWFLoader line 1497 the following

 
else if (byteArray)
{
    loader = new FlexLoader();
    child = loader;
    addChild(child);
 
    loader.contentLoaderInfo.addEventListener(
     Event.COMPLETE, contentLoaderInfo_completeEventHandler);
    loader.contentLoaderInfo.addEventListener(
     Event.INIT, contentLoaderInfo_initEventHandler);
    loader.contentLoaderInfo.addEventListener(
     Event.UNLOAD, contentLoaderInfo_unloadEventHandler);
 
    // if loaderContext null, it will use default, which is AppDomain
    // of child of Loader's context
    loader.loadBytes(byteArray, loaderContext);
}
 

You see the problem? No listener or dispatcher for the IOErrorEvent! So i had to load my bytes using FlexLoader(); and listen for the events myself.

1 Comment »

  1. Same issue wanted to have an error when downloading a non supported image e.g. TIF. Came with the 2044 exception. Had to catch it with an event in the ContentLoaderInfo class

    var loader:FlexLoader = new FlexLoader();
    loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, test);
    loader.addEventListener(IOErrorEvent.IO_ERROR, handler);
    loader.loadBytes(afbeelding);
    imageHolder.source = loader.content;

    this worked

    Comment by Spiral — September 25, 2009 @ 1:22 pm

RSS feed for comments on this post. | TrackBack URI

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .