nextframe()上的AS3 bitmapData;

时间:2012-11-21 19:16:25

标签: actionscript-3 bitmapdata

不是一个在这里挣扎的编码员:

尝试在下一帧中绘制当前帧作为cpu效率的位图。在AS2中,这段代码就像一个魅力:

import flash.display.*;
// # create the bitmap
var tBitmapData = new BitmapData(400, 200, true, 0x00000000);

// # now draw this movieClip's content to the bitmap
tBitmapData.draw(this);
// # 2nd frame should be blank!
nextFrame();
// # now attach the bitmap you made to this movieclip
this.attachBitmap(tBitmapData, 1, "auto", true);

只需要知道如何为AS3重写这个。谢谢!

1 个答案:

答案 0 :(得分:1)

首先,在AS3 BitmapData中不是DisplayObject。您需要将其包装到Bitmap对象中。然后用George Profenza提到的addChild替换attachBitmap:

import flash.display.*;
// # create the bitmap
var tBitmapData:BitmapData = new BitmapData(400, 200, true, 0x000000);

// # now draw this movieClip's content to the bitmap
tBitmapData.draw(this);
// # 2nd frame should be blank!
nextFrame();
// # now attach the bitmap you made to this movieclip
this.addChild(new Bitmap(tBitmapData));

还尝试输入变量(var tBitmapData:BitmapData)。这提高了性能并允许编译器捕获一些错误。