📄 edtimer.as
字号:
//------------------------------
import mx.utils.Delegate;
import mx.events.EventDispatcher;
//------------------------------
class AS2.utils.EDTimer extends EventDispatcher
{
//------------------------------
private var _timerID:Number;
private var _delay:Number;
private var _repeatCount:Number;
private var _currentCount:Number = 0;
private var _running:Boolean;
//------------------------------
/*
@parameter delay: 延迟,单位毫秒.
@parameter repeatCount: 重复次数.默认为Infinity(正无穷大);
*/
public function EDTimer(delay:Number, repeatCount:Number)
{
if (isNaN(delay)) {
return;
}
if (isNaN(repeatCount)) {
repeatCount = Infinity;
}
this._delay = delay;
this._repeatCount = repeatCount;
}
//------------------------------
public function reset():Void
{
this._currentCount = 0;
this.stop();
}
public function start():Void
{
this._timerID = setInterval(Delegate.create(this, this.startTimer), this._delay);
this._running = true;
}
public function stop():Void
{
clearInterval(this._timerID);
this._running = false;
}
public function toString():String
{
return "[EDTimer]";
}
//----------------------------------------
private function startTimer():Void
{
this._currentCount++;
this.dispatchEvent({type:"timer", currentCount:this._currentCount});
if (this._currentCount == this._repeatCount) {
this.reset();
this.dispatchEvent({type:"timerComplete"});
}
}
//------------------------------
public function get delay():Number
{
return this._delay;
}
public function set delay(d:Number):Void
{
this._delay = d;
}
public function get repeatCount():Number
{
return this._repeatCount;
}
public function set repeatCount(r:Number):Void
{
this._repeatCount = r;
}
public function get currentCount():Number
{
return this._currentCount;
}
public function get running():Boolean
{
return this._running;
}
//------------------------------
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -