來自help.adobe.com:
The Timer
class is the interface to timers, which let you run code on a specified time sequence. Use the start()
method to start a timer. Add an event listener
for the timer event to set up code to be run on the timer interval.
運用它的關鍵地方:
1. 首先定義好timer對象
public var _timer:Timer = new Timer(3000, 1);/*定時3秒鐘, 重複1次*/
timer對象的構造方法:
public function Timer(delay:Number, repeatCount:int = 0)
兩個參數,delay:間隔時間單位爲微妙,或是等待時間;repeatCount:重複次數,即指定timer計時器要作用幾次。
repeatCount默認情況爲0,可以無限次的使用,除非調用_timer.stop()。
2. 給timer對象新增事件監聽,即時間到了要乾的活
_timer.addEventListener(TimerEvent.TIMER, _onTimer);
private function _onTimer(e:TimerEvent):void
{
//add your statements
}
3.之前兩步是準備好所有的“作料”,下面是如何控制
1)什麼時候“按表”:_timer.start();
2)什麼時候“歸零”:_timer.reset();
3) 提前“停表”:_timer.stop();
正常的過程是start之後,設定的時間到了就觸發_onTimer幹活;