⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cftimer.as

📁 flash强大事件机制扩展类
💻 AS
字号:
//----------------------------------------
import mx.utils.Delegate;
//----------------------------------------
class AS2.utils.CFTimer
{
	//----------------------------------------
	private var _timerID:Number;
	private var _delay:Number;
	private var _repeatCount:Number;
	private var _currentCount:Number = 0;
	private var _running:Boolean;
	//----------------------------------------
	public var timer:Function;
	public var timerComplete:Function;
	//----------------------------------------
	/*
	@parameter	delay:			延迟,单位毫秒.
	@parameter	repeatCount:	重复的次数.默认值为Infinity(正无穷大);
	*/
	public function CFTimer(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 "[CFTimer]";
	}
	//----------------------------------------
	private function startTimer():Void
	{
		this._currentCount++;
		this.timer(this._currentCount);
		if (this._currentCount == this._repeatCount) {
			this.reset();
			this.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 + -