|
-
Using BitmapData to Draw a movieclip into another one
How to draw a movieclip into another movieclip using bitmapdata?
-
Senior Member
Hmm...you don't, really. For duplicating a MovieClip, you can say
Code:
var newMCClass:Class = someExistingMC.constructor;
var duplicate:DisplayObject = new newMCClass();
This was the Senocular approach, there's more about it here:
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.
-
half as fun, double the price
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));
-
Senior Member
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...
-
 Originally Posted by senocular
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));
Thanks. But it always draws to x=0 y=0. How can i draw to to a different area?
-
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);
...
-
 Originally Posted by 5TonsOfFlax
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 !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|