因为好像你可能使用的是actionscript 3,所以我建议不要使用间隔。 Timer对象可能更好,因为它可以提供更好的控制,例如可以设置在停止自身之前触发的次数,并且可以根据需要轻松启动,停止和重新启动计时器。
使用定时器对象并添加一个事件监听器用于每个蜱
import flash.utils.Timer;
import flash.events.TimerEvent;
// each tick delay is set to 1000ms and it'll repeat 12 times
var timer:Timer = new Timer(1000, 12);
function timerTick(inputEvent:TimerEvent):void {
trace("timer ticked");
// some timer properties that can be accessed (at any time)
trace(timer.delay); // the tick delay, editable during a tick
trace(timer.repeatCount); // repeat count, editable during a tick
trace(timer.currentCount); // current timer tick count;
trace(timer.running); // a boolean to show if it is running or not
}
timer.addEventListener(TimerEvent.TIMER, timerTick, false, 0, true);
控制计时器的
示例:
timer.start(); // start the timer
timer.stop(); // stop the timer
timer.reset(); // resets the timer
两个事件它抛出:
TimerEvent.TIMER // occurs when one 'tick' of the timer has gone (1000 ms in the example)
TimerEvent.TIMER_COMPLETE // occurs when all ticks of the timer have gone (when each tick has happened 11 times in the example)
API文档:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/Timer.html
打我吧;) – 2013-03-09 19:52:22
嘿,是的,和接近相同的代码! – Dave 2013-03-09 19:53:25
完美地工作:)谢谢 – 2013-03-09 19:53:54