因爲好像你可能使用的是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