Flash动作脚本:如何使用AS3在时间轴中逐帧动画获得公共延迟(ms)?

时间:2015-08-10 17:06:33

标签: actionscript-3 flash actionscript

我第一次使用Action Script 3。我想动画几帧,我想给每一帧延迟。我目前在每个帧上使用以下脚本,总共20帧。

stop();
setTimeout(function() { nextFrame(); }, 100);

如果我想增加/减少延迟,我必须改变每一帧中的值。我很确定我没有采取聪明的方式。请帮帮我。感谢高级专家。

1 个答案:

答案 0 :(得分:1)

虽然最简单的解决方案是将帧速率调整为10fps(相当于幻灯片之间的100ms),但有些原因可能不合适(时间线内的动画等)。

也许Timer会更好。

这样的事情:

import flash.utils.Timer;
import flash.events.TimerEvent;

//create a timer
var timer:Timer = new Timer(100); //fire every 100ms

//listen for it's tick, and run the timerTick function every interval
timer.addEventListener(TimerEvent.TIMER, timerTick);

//start the timer
timer.start();


function timerTick(e:Event):void {
    //if the next frame is the last frame, stop the timer
    if(this.currentFrame == this.totalFrames - 1){
        timer.stop();
    }

    //go to the next frame
    nextFrame();
}

在您的各个帧上,您可以调整定时器的延迟(滴答前多长时间)或一起停止定时器。如果您想在某个时刻暂停用户交互,或者为某些帧设置更长/更短的延迟,这可能会有所帮助。

timer.delay = 200;

timer.stop();