Search code examples
actionscript-3flashmovieclipbitmapdataadobe-illustrator

Bitmapdata.draw(MovieClip) Gives Blank BitmapData


I'm predrawing all vector element in my game to bitmaps to improve performance - the vector elements are exported as swf files from Illustrator (I suspect that is part of the problem). When embedding the swf file in as3 like so:

[Embed(source = 'file.swf')] private static const image:Class; 

And then adding it to the stage, like so

stage.addChild(new image);

Everything is fine, but if instead I draw it to a bitmap data like so...

genericBitmapData.draw(new image);

It's a blank bitmapdata. I've tried using gotoAndStop on frames 0 and 1 before drawing with no avail. Does anyone have experience with the swf files that Illustrator exports and any insight as to how I can get these drawing as expected?

Here is a link to a really simple .swf that produces the same results


Solution

  • Here's my revised solution:

    //create movieclip
    var mc:MovieClip = new image();
    addEventListener(Event.ENTER_FRAME, enterFrameHandler);
    
    //this gets called on next frame
    function enterFrameHandler(event:Event):void
    {
        removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
        genericBitmapData.draw(mc);
    }