With the availability of the BitmapData() class that comes bundled with Flash 8, we can "duplicate" the content by attaching its data to an empty movie clip. For example, if you use the MovieClipLoader() class to load your dynamic content, you would want to duplicate your movie clip when it's loaded:
- mclListener.onLoadInit = function(target) {
var mc_copy = target._parent.createEmptyMovieClip("mc_copy", 34532);
var bd = new flash.display.BitmapData(target._width, target._height);
bd.draw(target);
mc_copy.attachBitmap(bd, target._parent.getNextHighestDepth());
}
Inside the code block, the first line creates an empty movie clip to which we will use to hold the duplicated image.
- var mc_copy = target._parent.createEmptyMovieClip("mc_copy", 34532);
The second line then creates a new BitmapData object that will store the properties of the image to be duplicated.
- var bd = new flash.display.BitmapData(target._width, target._height);
The third line draws, or stores your original image to the BitmapData object.
- bd.draw(target);
Finally, simply attach the BitmapData object to your mc_copy. Your empty movie clip now contains a duplicated image of your dynamically loaded content.
- mc_copy.attachBitmap(bd, target._parent.getNextHighestDepth());
Download a simple example here.
1 comments:
Yep really cool...
check out what Zeh Fernando made, taking this to the next level.
http://svn.zeh.com.br/actionscript_classes/as2/zeh/loading/ImageLoader.as
http://svn.zeh.com.br/actionscript_classes/as2/zeh/loading/ImageQueue.as
Post a Comment