home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
404 Jogos
/
CLJG.iso
/
Puzzle
/
Easter_Eggs.swf
/
scripts
/
__Packages
/
com
/
novelgames
/
flashgames
/
commonAS2
/
NewTimer.as
< prev
next >
Wrap
Text File
|
2008-09-04
|
4KB
|
105 lines
class com.novelgames.flashgames.commonAS2.NewTimer implements com.novelgames.flashgames.commonAS2.Timer
{
static var paused = false;
static var totalPausedTime = 0;
function NewTimer(delay, repeatCount)
{
if(repeatCount == undefined)
{
repeatCount = 0;
}
this.delay = delay;
this.repeatCount = repeatCount;
this.currentCount = 0;
}
static function getTimer()
{
if(com.novelgames.flashgames.commonAS2.NewTimer.paused)
{
return com.novelgames.flashgames.commonAS2.NewTimer.pauseTime - com.novelgames.flashgames.commonAS2.NewTimer.totalPausedTime;
}
return getTimer() - com.novelgames.flashgames.commonAS2.NewTimer.totalPausedTime;
}
static function pause()
{
if(com.novelgames.flashgames.commonAS2.NewTimer.paused)
{
return undefined;
}
com.novelgames.flashgames.commonAS2.NewTimer.paused = true;
com.novelgames.flashgames.commonAS2.NewTimer.pauseTime = getTimer();
}
static function unpause()
{
if(!com.novelgames.flashgames.commonAS2.NewTimer.paused)
{
return undefined;
}
com.novelgames.flashgames.commonAS2.NewTimer.paused = false;
com.novelgames.flashgames.commonAS2.NewTimer.totalPausedTime += getTimer() - com.novelgames.flashgames.commonAS2.NewTimer.pauseTime;
}
function addEventListener(type, listenerObject, listenerFunctionName)
{
if(type != com.novelgames.flashgames.commonAS2.TimerEvent.TIMER)
{
return undefined;
}
this.listenerObject = listenerObject;
this.listenerFunctionName = listenerFunctionName;
}
function removeEventListener(type)
{
if(type != com.novelgames.flashgames.commonAS2.TimerEvent.TIMER)
{
return undefined;
}
this.listenerObject = null;
this.listenerFunctionName = null;
}
function start()
{
this.adjustedStartTime = com.novelgames.flashgames.commonAS2.NewTimer.getTimer();
this.usingDelay = this.delay;
clearInterval(this.intervalID);
this.intervalID = setInterval(this,"timerEventListener",this.delay);
}
function stop()
{
clearInterval(this.intervalID);
}
function timerEventListener()
{
this.currentCount = this.currentCount + 1;
if(com.novelgames.flashgames.commonAS2.NewTimer.paused)
{
clearInterval(this.intervalID);
this.usingDelay = Math.max(this.delay - (com.novelgames.flashgames.commonAS2.NewTimer.getTimer() - this.adjustedStartTime),1);
this.currentCount = this.currentCount - 1;
this.intervalID = setInterval(this,"timerEventListener",this.usingDelay);
return undefined;
}
if(com.novelgames.flashgames.commonAS2.NewTimer.getTimer() - this.adjustedStartTime >= this.delay)
{
this.adjustedStartTime = com.novelgames.flashgames.commonAS2.NewTimer.getTimer();
if(this.usingDelay != this.delay)
{
clearInterval(this.intervalID);
this.usingDelay = this.delay;
this.intervalID = setInterval(this,"timerEventListener",this.usingDelay);
}
this.listenerObject[this.listenerFunctionName](new com.novelgames.flashgames.commonAS2.TimerEvent());
if(this.repeatCount != 0 && this.currentCount >= this.repeatCount)
{
clearInterval(this.intervalID);
}
}
else
{
clearInterval(this.intervalID);
this.usingDelay = Math.max(this.delay - (com.novelgames.flashgames.commonAS2.NewTimer.getTimer() - this.adjustedStartTime),1);
this.currentCount = this.currentCount - 1;
this.intervalID = setInterval(this,"timerEventListener",this.usingDelay);
}
}
}