home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mobiclic 161
/
MOBICLIC161.ISO
/
pc
/
DATA
/
DSS161
/
DSS161_00
/
DSS161_00.swf
/
scripts
/
dss161
/
engineaddons
/
gamesprotos
/
actors
/
actorClip
/
ActorTimer.as
< prev
next >
Wrap
Text File
|
2014-01-15
|
5KB
|
175 lines
package dss161.engineaddons.gamesprotos.actors.actorClip
{
import dss161.engineaddons.facades.GameEngine;
import dss161.engineaddons.gamesprotos.Actor;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.utils.getTimer;
public class ActorTimer extends Actor
{
protected var timer:Timer;
protected var _duration:Number = 999999999;
protected var _delay:Number = 10;
protected var _repeatCount:Number = 0;
protected var _callback:Function = null;
protected var _onTic:Function = null;
protected var timeStart:Number = 0;
protected var timeLast:Number = 0;
protected var timerToWake:Boolean = false;
public function ActorTimer(param1:GameEngine, param2:*)
{
super(param1,null,param2);
if(param2.duration != undefined)
{
this._duration = param2.duration;
}
if(param2.delay != undefined)
{
this._delay = param2.delay;
}
if(param2.callback != undefined)
{
this._callback = param2.callback;
}
if(param2.onTic != undefined)
{
this._onTic = param2.onTic;
}
this.timer = new Timer(this._delay,this._repeatCount);
}
public static function create(param1:GameEngine, param2:*) : ActorTimer
{
return new ActorTimer(param1,param2);
}
protected function timerEventTic(param1:TimerEvent) : void
{
this._onTic(this);
}
protected function timerEventDuration(param1:TimerEvent) : void
{
this.timeLast = getTimer();
if(this.timeLast - this.timeStart > this._duration)
{
this.stop();
this._callback(this);
}
}
override protected function _sleep() : void
{
super._sleep();
if(isSleeping)
{
return;
}
isSleeping = true;
if(this.timer.running)
{
this.timerToWake = true;
this.timer.stop();
}
}
override protected function _wake() : void
{
var _loc1_:Number = NaN;
super._wake();
if(isSleeping = false)
{
return;
}
isSleeping = false;
if(this.timerToWake)
{
this.timerToWake = false;
_loc1_ = getTimer() - this.timeLast;
this.timeStart += _loc1_;
this.timeLast += _loc1_;
this.timer.start();
}
}
override protected function _destroy() : void
{
super._destroy();
if(this.timer != null)
{
this.stop();
this.timer = null;
this._callback = null;
}
}
public function get currentCount() : int
{
return this.timer.currentCount;
}
public function get delay() : Number
{
return this.timer.delay;
}
public function set delay(param1:Number) : void
{
this.timer.delay = param1;
}
public function get repeatCount() : int
{
return this.timer.repeatCount;
}
public function set repeatCount(param1:int) : void
{
this.timer.repeatCount = param1;
}
public function reset() : void
{
this.timer.reset();
}
public function get running() : Boolean
{
return this.timer.running;
}
override public function start() : void
{
if(this._onTic != null)
{
this.timer.addEventListener(TimerEvent.TIMER,this.timerEventTic);
}
else if(this._callback != null)
{
this.timer.addEventListener(TimerEvent.TIMER,this.timerEventDuration);
}
this.timeStart = getTimer();
this.timer.start();
}
public function stop() : void
{
this.timer.removeEventListener(TimerEvent.TIMER,this.timerEventTic);
this.timer.removeEventListener(TimerEvent.TIMER,this.timerEventDuration);
this.timer.stop();
}
}
}