BetaDesigns( Blog ) Flex and Component Development

18Mar/091

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

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.

Comments (1) Trackbacks (0)
  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


Leave a comment

(required)

No trackbacks yet.