Показать сообщение отдельно
Старый 04.03.2009, 18:28
qazwsx вне форума Посмотреть профиль Найти все сообщения от qazwsx
  № 12  
Ответить с цитированием
qazwsx
Banned

Регистрация: Mar 2008
Адрес: Krasnoyarsk
Сообщений: 587
Код AS1/AS2:
import mx.events.EventDispatcher;
 
/**
 * 	Класс инкапсулирующий работу SetInterval/clearInterval 
 *  работает через событие 
 * */
class utils.Timer extends mx.events.EventDispatcher
{
 
	public static var TICK_EVENT:String = "TICK_EVENT";
	private static var SECONDE:Number = 1000;
 
	var interValId:Number;
 
	var _duration:Number;
 
	public function Timer( duration:Number )
	{
		super();
		this._duration = duration*SECONDE;
		this.interValId = undefined;
	}
 
	public function turnOn():Void
	{
 
		//trace( "tutils.Timer.urnOn " + this.durationMillSec );
 
		if ( enable )
			this.turnOff();
 
		this.interValId = setInterval( Delegate.create( this , onIntervalHandler ) , this.durationMillSec );
 
	}
 
	public function turnOff():Void
	{
 
		this.clearInternalInterval();
	}
 
 
	public function get enable():Boolean
	{
		return interValId != undefined;
	}
 
	public function set enable( val:Boolean ):Void
	{
		if ( val == this.enable )
		{
			return;
		}
 
		if ( val )
			turnOn();
		else
			turnOff();
	}
 
	public function reset():Void
	{
		this.turnOff();
		this.turnOn();
	}
 
	public function get durationMillSec():Number
	{
		return this._duration;
	}
 
	public function set durationMillSec(arg:Number):Void
	{
		this._duration = arg;
		reset();
	}
 
	public function get durationSeconds():Number
	{
		return durationMillSec/SECONDE;
	}
 
	public function set durationSeconds(arg:Number):Void
	{
		this.durationMillSec = arg*SECONDE;
	}
 
 
	private function onIntervalHandler():Void
	{
		this.dispatchEvent( { type:TICK_EVENT } );
	}
 
	private function clearInternalInterval():Void
	{
 
		if ( !this.enable )
			return;
 
		clearInterval( this.interValId );
		this.interValId = undefined;
 
	}
 
 
 
 
 
}
Если ты попросиш пример привести я уничтожу тебя, и всех кто тебя когда либо знал :E


Последний раз редактировалось qazwsx; 04.03.2009 в 18:31.