我有一个使用Flash Pro CS6内置的着色书应用程序。我使用以下代码将要着色的形状添加到名为“coloringBook”的对象中:
for (var i = 0; i <= colorable.totalFrames; i ++) {
shape = new (getDefinitionByName(pattern) as Class)();
shape.gotoAndStop(i + 1);
coloringBook.addChild(shape);
shape.x = Math.abs(gWidth - dWidth)/2;
shape.y = Math.abs(gHeight - dHeight)/2;
if (i < colorable.totalFrames) {shape.addEventListener(MouseEvent.CLICK, colorColorable);}
}
虽然代码工作得很好,但我希望通过向用户显示添加到舞台的每个形状来为应用添加一些润色。我可以在代码中添加暂停(例如睡眠计时器),但应用程序只是空白,直到所有计时器都完成并显示完成的形状编译。任何关于编码的指导都将非常感激。
答案 0 :(得分:0)
您可以尝试使用enter_frame每帧创建一个形状。也许是这样的:
var currentIndex:int = 0;
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
private function enterFrameHandler(e:Event):void
{
shape = new (getDefinitionByName(pattern) as Class)();
shape.gotoAndStop(currentIndex + 1);
coloringBook.addChild(shape);
shape.x = Math.abs(gWidth - dWidth)/2;
shape.y = Math.abs(gHeight - dHeight)/2;
if (currentIndex < colorable.totalFrames)
{
shape.addEventListener(MouseEvent.CLICK, colorColorable);
}
else
{
stage.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
currentIndex++;
}