How to draw a movieclip into another movieclip using bitmapdata?
Printable View
How to draw a movieclip into another movieclip using bitmapdata?
Hmm...you don't, really. For duplicating a MovieClip, you can say
This was the Senocular approach, there's more about it here:Code:var newMCClass:Class = someExistingMC.constructor;
var duplicate:DisplayObject = new newMCClass();
http://www.kirupa.com/forum/showthread.php?p=1939827
That will get you a new instance of the same type of object as the first, but it won't preserve any state, such as graphics drawn with the drawing API, or alpha, or children.
If you just want to clone the appearance of a movieclip, you can draw it into a bitmapdata using the draw method, then use that bitmapdata to create a Bitmap, or as many Bitmaps as you want. This of course also won't preserve any actual state, just appearance. And I don't think it'll preserve filter effects.
draw[ing] a movieclip into another movieclip using bitmapdata:
Code:// assumes content filled mc1 and empty mc2
var bmp:BitmapData = new BitmapData(mc1.width, mc1.height, true, 0);
bmp.draw(mc1);
mc2.addChild(new Bitmap(bmp));
the master weighs in...
yeah, I'm a dope. But that constructor method sure works nicely for pre-drawn MCs or loaded JPGs...I just used it to make a singleton class that loads sprite sheets one time only and then returns copies of them on request, no drawing of bitmap data necessary...I have to assume it runs a little faster, too...
Thanks. But it always draws to x=0 y=0. How can i draw to to a different area?Quote:
Originally Posted by senocular
Take a look at the livedocs for BitmapData.draw. http://livedocs.adobe.com/flash/9.0/...itmapData.html
You see that you can pass a matrix. That matrix can apply typical affine transforms such as scaling, rotation, and translation to the drawn object. So, to draw at say (20, 20), you could do this:
Code:...
var m:Matrix = new Matrix();
m.translate(20, 20);
bmp.draw(mc1, m);
...
thanks !Quote:
Originally Posted by 5TonsOfFlax