Duplicate Loader object

over 2 years ago malczak actionscript comments

Is it possible to clone Loader instance to save some bandwidth?

Yes, this is possible.

Solution of this problem depends on type of loaded media. Lets take a look on how to clone loaded media.

If you've loaded image (png, jpg or gif) file, and you're not going to do any pixel level manipulation

var s:Bitmap = new Bitmap( (oldLoader.getChildAt(0) as Bitmap).bitmapData ) 

using this to create multiple bitmaps can also save used memory - only one BitmapData instance is created and shared across all bitmaps.

If you need to do any pixel level editing, its important to first clone BitmapData!

If you've loaded swf file. You can clone Loader and use its loadBytes public method to load already loaded data

newLoader.loadBytes( oldLoader.contentLoaderInfo.bytes )

Comments

over 1 year ago Tuan Minh #0

You must be really lazy..

How come you put codes on your site and never test if it can run or not.

over 1 year ago malczak #1

lol...
both codes works fine... it looks like You need to practice more if You had any problems with them :)

6 months ago helloworlder http://www.helloworlder.com #2

Thanks! Very helpful code. Not only saves bandwidth, but much more elegant than loading multiple times :-)

New comment

  1. (never shown, just for us for possible contact)

  2. (with http or https prefix)

  3. (use [code][/code] tags to post a code snippet)

  4. (javascript is required)

Website content premeditately commited by segfaultlabs (malczak & sobstel).
Layout by mlando. Icons by DryIcons.com. All rights reserved, of course.