0

我有一个内置在 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);}
}

虽然代码运行得非常好,但我希望通过向用户展示添加到舞台的每个形状来为应用程序添加一些润色。我可以在代码中添加暂停(例如睡眠定时器),但应用程序只是空白,直到所有定时器都完成并显示完成的形状编译。任何有关编码的指导将不胜感激。

4

1 回答 1

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++;
}
于 2013-09-30T01:40:48.277 回答