Gordon's original answer, which is that the Image or SWFLoader components dispatch ioError events, should still apply. If you set an event listener for the flash.events.IOErrorEvent.IO_ERROR event, then it should get dispatched if the image file can't be found. Make sure you're listening for the right event, assuming you are there shouldn't be a reason it wouldn't get dispatched.

Alternatively, you could go another route, which is to define a custom skin for broken images. SWFLoader and Image allow you to specify the brokenImageSkin, which will be used to render the visual display of an image that couldn't be loaded. You could set this to your "no picture" blank image and then if the image can't be found it would display as you want it to.


Robb Cundick wrote:

Thanks for the reply.

I did try just setting an image component's source property at runtime. It works fine if the image is there but if there is no image it just shows a blank (with a red "x") and doesn't generate an error.

The reason I need to catch the error is that I am building a directory application for an organization. Some people in the directory will have a picture, but some will not. All pictures will reside in a folder at the server end and be accessed via a URL. When a person's directory record is loaded I will build the name of their picture using their directory record ID. If a picture with that name cannot be found, I want to display an alternate image (a blank image that says "no picture").

So I just need some way to know if the picture file doesn't exist, in which case I will point the image component to the blank image.



*From:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On Behalf Of *Gordon Smith
*Sent:* Friday, February 09, 2007 1:21 AM
*To:* flexcoders@yahoogroups.com
*Subject:* RE: [flexcoders] Catching IOError on Loader

Loader doesn't dispatch an ioError event. (It isn't listed in the ASDoc for Loader at http://livedocs.macromedia.com/flex/201/langref/index.html <http://livedocs.macromedia.com/flex/201/langref/index.html>.) This event is dispatched by the Loader's contentLoaderInfo object., which is an instance of LoaderInfo. I don't remember at the moment why the Player's Loader is designed this way.

Flex's SWFLoader and Image components do dispatch ioError events.

- Gordon


*From:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On Behalf Of *Robb Cundick
*Sent:* Thursday, February 08, 2007 11:16 PM
*To:* flexcoders@yahoogroups.com
*Subject:* [flexcoders] Catching IOError on Loader

Hello, all:

I am using a Loader to retrieve a jpeg file that may or my not exist. If it doesn't exist, I'm getting an Actionscript error message:

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

I would like to catch this error and handle it gracefully; however I have not been able to figure out how to catch it. Try/catch doesn't work (probably because it's an asynchronous process). But I also tried adding an event listener as follows:

function myPictureLoader()


  var pictLdr:Loader = new Loader();

  var pictURL:String = "photos/NzPicture.jpg"

  var pictURLReq:URLRequest = new URLRequest(pictURL);

  pictLdr.addEventListener(IOErrorEvent.IO_ERROR, handleIOError);

pictLdr.load(pictURLReq); }
function handleIOError(event:IOErrorEvent) : void {

  Alert.show('file not found', 'IO error');

} However the listener function never fires and I still get the Actionscript error box popping up. Any ideas?


Robb Cundick

Reply via email to