views:

489

answers:

1

Hi,

in my mxml file I have images declared like this:

 <mx:Image x="0" y="0" source="assets/bigpicture.png" id="picture1"/>

and at some event I do:

picture1.source = "assets/bigpicture2.png";

However this results in flex removing the picture, and when it has loaded it will show it again.

How can I make the mx:image make so that it will continue to show the image until the new image has been loaded?

thanks!

+2  A: 

Why don't you just embed your assets in your application if they are always the same ?

If your images must be loaded at runtime: I think the only way to do it is to load the asset separately from the Image with a Loader, and when the Loader has finished loading, assign it as source of the Image.

Else, you can just fade the Image to alpha=0 before switching the source, and then fade it back to 1.0. It will look smoother, but there will still be no image displayed while the new one is loading.

Julien Nicoulaud
embedding is no option since they are huge and there are lots.Fading is also no option as it has to transition immediately.
Toad
Then loading via a Loader and then setting it into the image is probably your best bet. That's essentially "double buffering" and there's not going to be much faster than that.
Michael Todd
By the way, looks like Flex 4 has an effect for smoothly switching images : http://blog.flexexamples.com/2009/09/21/fading-two-images-using-the-crossfade-effect-in-flex-4/ .
Julien Nicoulaud