0
votes

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

2
Hi. Can you publish somewhere example of such swf file? - kostik
@kostik I added a link to the end of the question. - Pinpickle
What are the dimensions of the genericBitmapData ? - prototypical
@prototypical It varies depending on context, though now I'm making it so it's the width of the movieclip for testing purposes (taking scaling into account as well) - Pinpickle
I think I find reason. Try this code: pastebin.com/YgamqtKU Loader instance never fire any event. And from Event.ENTER_FRAME handler for me it trace: [object AVM1Movie]. And AVM2 swf will not able to draw AVM1Movie. Try change export parameters in Illustrator - kostik

2 Answers

0
votes

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

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.