ActionScript 2: Copy MovieClips with BitmapData on runtime

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);
  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.

One response to “ActionScript 2: Copy MovieClips with BitmapData on runtime”

Leave a Reply

Your email address will not be published. Required fields are marked *