views:

1187

answers:

4

When loading images using Loader, what's the preferred way to add the image to the display list? Grabbing the data in an Event.COMPLETE handler like new Bitmap( Bitmap(LoaderInfo(e.target).content).bitmapData ) , or adding the Loader instance itself?

+1  A: 

It is better to wait for the Loader to complete and set the Image data in the result handler.

dirkgently
ok, why? does the loader also need to be added to the display list? curious, the example from adobe does.
Ronn
So that you can handle failure, don't start processing the Image before it's loaded and so on...
dirkgently
+3  A: 

If you only want to display the Loader's content, then feel free to add the Loader to the display list rather than extracting its contents. It's an uncommon situation when you'll need to reparent a Loader's content.

Additionally, it's worth noting that a Loader's content will not always be accessible. For instance, Flash Player places security restrictions on content loaded from other domains. When these stronger security rules are enforced, Flash Player throws security errors at runtime if you try to access the Loader's content.

joshtynjala
so if I'm looping thru say 25 images, I'd add 25 loaders to the display?
Ronn
Yes. As a reference point. Flex's SWFLoader/Image controls use Loader internally, and they add the Loader to the display list rather than extracting the Loader's content first.
joshtynjala
A: 

Bitmap supports image smoothing when resizing and that's handy sometimes. On the other hand, Loader is DisplayObjectContainer and allows adding other children inside.

Tomislav Pokrajcic
A: 

Loader is handy as it makes data handling quite neat (loading/unloading). Personally I'd need to have a good reason to extract data from a loader object.

In the case of an image a good reason would be that whatever your doing with the data reqires the BitmapData class.

If you are simply displaying the image then you wont necessaraly need the BitmapData class. In this case working with BitmapData is alota code ya dont need!

rur