The flash.display.BitmapData class enables you to copy arbitrary movie clips on runtime, e.g. movie clips attached from the library or external loaded images or swf files. Here is a little helper function that does all the magic stuff:
import flash.display.BitmapData;
/**
* @param sourceMovieClip Movie clip to copy
* @param targetMovieClip (Empty) movie to past into
*/
function copy(sourceMovieClip:MovieClip, targetMovieClip:MovieClip):Void {
var bitmapData:BitmapData = new BitmapData(sourceMovieClip._width, sourceMovieClip._height, false, 0xFFFFFF);
bitmapData.draw(sourceMovieClip);
targetMovieClip.attachBitmap(bitmapData, 1);
}It is important to know, that the copy function only creates a “visual copy” and does not copy any functionalities or timelines; the copy function works like “make a screenshot of the source movie clip and past it to the target movie clip”. Nevertheless, this function could be very useful to copy e.g. dynamic loaded images.
A running example (Flash CS3) can be found here.
Related posts:
- ActionScript 2: Bugfixes in “ActionScript 2.0 Arabic Parsing v1.2”
- ActionScript 2: Cast object to array
- ActionScript 2: Create dynamic FLVPlaybacks with attachMovie
- ActionScript 2: Create dynamic text fields with Arabic texts
- ActionScript 2: Bugfixes in “ActionScript 2.0 Arabic Parsing v1.2” – Part 2
The flash.display.BitmapData class enables you to copy arbitrary movie clips on runtime, e.g. movie clips attached from the library or external loaded images or swf files. Here is a little helper function that does all the magic stuff:
import flash.display.BitmapData;
/**
* @param sourceMovieClip Movie clip to copy
* @param targetMovieClip (Empty) movie to past into
*/
function copy(sourceMovieClip:MovieClip, targetMovieClip:MovieClip):Void {
var bitmapData:BitmapData = new BitmapData(sourceMovieClip._width, sourceMovieClip._height, false, 0xFFFFFF);
bitmapData.draw(sourceMovieClip);
targetMovieClip.attachBitmap(bitmapData, 1);
}
It is important to know, that the copy function only creates a "visual copy" and does not copy any functionalities or timelines; the copy function works like "make a screenshot of the source movie clip and past it to the target movie clip". Nevertheless, this function could be very useful to copy e.g. dynamic loaded images.
A running example (Flash CS3) can be found here.