/*---------------------------------------------------------------------------------------- * (c) 2001, ATOMGAS Luzifer Altenberg, luzifer@atomgas.de * http://atomgas.de luzifer@atomgas.de * * timerObj to easy time handling and Pausing * * version 1.2 <8.12.2001> * * do not remove this part! /----------------------------------------------------------------------------------------*/ Timer = function(lifeTime){ this.lifeTime = Number(lifeTime); this.debug = false; this.startTime = getTimer(); this.runTime = 0; this.remainingTime = this.lifeTime; this.setPause(0); }; Timer.prototype._update = function(){ this.runTime = (getTimer()-this.startTime)/1000; this.remainingTime = this.lifeTime-this.runTime; } Timer.prototype._update2 = function(){ if(this.pause) this.runTime = (this.pauseStartTime-this.startTime)/1000; else this.runTime = (getTimer()-this.startTime)/1000; this.remainingTime = this.lifeTime-this.runTime; } Timer.prototype.getRunTime = function(){ return this.runTime; } Timer.prototype.getRemainingTime = function(){ return this.remainingTime; } Timer.prototype.setPause = function (state){ if(state != this.pause){ if(state){ this.update = null; this.state = "paused"; this.pause = true; this.pauseStartTime = getTimer(); this._update2(); }else{ this.state = "running"; this.pause = false; this.startTime += getTimer()-this.pauseStartTime; this.update = this._update; this.update(); } } }; Timer.prototype.setTime = function (time){ this.startTime += (this.runTime-Number(time))*1000; this._update2(); }; Timer.prototype.setLifeTime = function (time){ this.lifeTime = Number(time); this._update2(); }; Timer.prototype.addLifeTime = function (time){ this.lifeTime += Number(time); this._update2(); }; Timer.prototype.getState = function (){ return this.state; }; Timer.prototype.isPaused = function (){ return this.pause; }; Timer.prototype.inTime = function (){ this.update(); return (this.runTime < this.lifeTime || this.lifeTime == null); }; Timer.prototype.restart = function (lifeTime){ this.lifeTime = Number(lifeTime); this.startTime = getTimer(); this.runTime = 0; this.remainingTime = Number(lifeTime); this.setPause(0); }; Timer.prototype.getMinutes = function(input){ var min = int(input/60); var sec = int(input%60); return (min < 10 ? "0"+min : min )+":"+ (sec < 10 ? "0"+sec : sec); }; //---------------------------------------------------------------------- trace(">>>timer.as - v 1.2 (c) ATOMGAS,2001");