Question

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

Was it helpful?

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

OTHER TIPS

So it turns out that the object needs to be instantiated before I can use it to draw, and the easiest way to detect when that is is to listen for the ENTER_FRAME event:

(new image).addEventListener(Event.ENTER_FRAME, functionToDrawImage);

And when that function is called, it will be ready to draw to a bitmapdata, and then all is right with the world.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top