PDA

View Full Version : Handling image load errors in a textfield


wagster
09-13-2009, 10:24 PM
So... I have a textfield with a number of embedded images, each with an id of "0", "1", "2" etc...

I have a short function that counts through all the images in the textfield, however many there may be, and adds an IOErrorEvent listener to each one.

The error handler then gets a reference to the LoaderInfo object which is associated with the Loader object that is failing to load an image. The LoaderInfo object has a "loader" property which provides a reference to the Loader object. I want to tell that Loader object to close() it's current load operation and then pass it a new URLRequest and load something else instead.

Problem is, when I call LoaderInfo.loader.close() I get:

Error #2099: The loading object is not sufficiently loaded to provide this information.

How do I access the Loader object and tell it to load something else?

Here's the code:

private function addImageListeners():void{
var i:int = 0;
while (displayBox.getImageReference(i.toString()) != null){
var l:Loader = displayBox.getImageReference(i.toString()) as Loader;
l.contentLoaderInfo.addEventListener(IOErrorEvent. IO_ERROR,IOErrorHandler;
i++;
}
}

private function IOErrorHandler (e:IOErrorEvent):void{
trace ("ERROR EVENT CAUGHT BY IOErrorHandler");
e.target.loader.close();
}

snickelfritz
09-13-2009, 10:27 PM
I wasn't aware that a textfield could be used as a display object container.
Is it true that you can load images into a textfield?

wagster
09-14-2009, 08:34 AM
It seems to be some sort of bodge job by Adobe. TextField doesn't inherit from DisplayObjectContainer so obviously you can't use it as one. Yet if you embed an image into a TextField using an <img> tag in htmlText and give it an id, Flash will create a Loader object to load the image and "add" it to the TextField using some sort of voodoo. The Loader is then accessed using the TextField's method getImageReference(id).

It's a pain to work with though, because it's a bodge. Wish I'd used AIR.