A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Using BitmapData to Draw a movieclip into another one

  1. #1
    Member
    Join Date
    Aug 2006
    Posts
    77

    Arrow Using BitmapData to Draw a movieclip into another one

    How to draw a movieclip into another movieclip using bitmapdata?

  2. #2
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    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

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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.

  4. #4
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358
    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));

  5. #5
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    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...

  6. #6
    Member
    Join Date
    Aug 2006
    Posts
    77
    Quote 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?

  7. #7
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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);
    ...

  8. #8
    Member
    Join Date
    Aug 2006
    Posts
    77
    Quote 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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center