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

📄 asbtimer.as

📁 flash强大事件机制扩展类
💻 AS
字号:
//----------------------------------------
import AS2.utils.CFDelegate;
//----------------------------------------
class AS2.utils.AsBTimer extends AsBroadcaster
{
	//----------------------------------------
	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 AsBTimer(delay:Number, repeatCount:Number)
	{
		AsBroadcaster.initialize(AsBTimer.prototype);
		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(CFDelegate.create(this, this.startTimer), this._delay);
		this._running = true;
	}
	public function stop():Void
	{
		clearInterval(this._timerID);
		this._running = false;
	}
	public function toString():String
	{
		return "[AsBTimer]";
	}
	//----------------------------------------
	private function startTimer():Void
	{
		this._currentCount++;
		this.broadcastMessage("timer", this._currentCount);
		if (this._currentCount == this._repeatCount) {
			this.reset();
			this.broadcastMessage("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 + -