tags:

views:

19

answers:

2

Hello. I'm using flex 4.1 to write an application and I was wondering how can I configure that whenever I try to load an image and the link is broken it will show a different image that i have embedded into my application.

I'm loading an Image using mx:Image.

thanks

+1  A: 

In the HTTP Request you can add a IO Error Event. When this event is triggered, you can use the embedded image instead.

VeeWee
can you please provide a brief example ?
ufk
I don't have code like this on my library. But what you do is:On creationcomplete of the component/module/application you try to catch the image. You can do this with an URLRequest + Loader. On this request you add a IOErrorEvent.IO_ERROR listerner and an Event.COMPLETE listener.When the error event is triggered, you just make a new instance of Image with as source the embeded image.When the complete event is triggered, you can just place the loader on the screen.Sample code at: http://livedocs.adobe.com/flex/3/langref/flash/display/Loader.html
VeeWee
this solution will work but it may be a bit too much work just to resolve broken images issues.
ufk
+1  A: 

You can do this by setting the brokenImageSkin on the mx:Image to whatever image you'd like. That way your Images will default to the specified image when loading fails. Here's an example: http://blog.flexexamples.com/2008/03/02/setting-a-custom-broken-image-skin-for-the-image-control-in-flex/

Wade Mueller
I resolved it by setting the brokenImageSkin attribute of the mx:Image to a class that I created with the requested image embeded: [Embed(source='pics/broken_user_image.jpg')] private var brokenImage:Class;
ufk