home *** CD-ROM | disk | FTP | other *** search
- class com.leadpipe.attentionhog.Timer
- {
- var object;
- var methodName;
- var minTime;
- var maxTime;
- var time;
- var timeStart;
- var id;
- var isPaused;
- var timeRemaining;
- static var instanceList = new Array();
- function Timer(o, m, min, max)
- {
- com.leadpipe.attentionhog.Timer.instanceList.push(this);
- this.object = o;
- this.methodName = m;
- this.minTime = min;
- this.maxTime = max;
- }
- function start()
- {
- this.time = this.randomInt(this.minTime,this.maxTime);
- this.timeStart = getTimer();
- if(this.id != null)
- {
- clearTimeout(this.id);
- }
- this.id = setTimeout(this,"doMethod",this.time);
- }
- function doMethod()
- {
- this.object[this.methodName]();
- this.start();
- }
- function pause(p)
- {
- this.isPaused = p;
- if(this.isPaused)
- {
- if(this.id != null)
- {
- clearTimeout(this.id);
- }
- this.timeRemaining = this.time - (getTimer() - this.timeStart);
- }
- else
- {
- this.timeStart = getTimer();
- if(this.id != null)
- {
- clearTimeout(this.id);
- }
- this.id = setTimeout(this,"doMethod",this.timeRemaining);
- }
- }
- function stop()
- {
- if(this.id != null)
- {
- clearTimeout(this.id);
- }
- }
- function clear()
- {
- if(this.id != null)
- {
- clearTimeout(this.id);
- }
- }
- function destroy()
- {
- this.clear();
- for(var _loc2_ in com.leadpipe.attentionhog.Timer.instanceList)
- {
- if(com.leadpipe.attentionhog.Timer.instanceList[_loc2_] == this)
- {
- com.leadpipe.attentionhog.Timer.instanceList.splice(_loc2_,1);
- break;
- }
- }
- }
- function §set§(min, max)
- {
- this.minTime = min;
- this.maxTime = max;
- }
- function randomInt(min, max)
- {
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- static function destroyAll()
- {
- for(var _loc1_ in com.leadpipe.attentionhog.Timer.instanceList)
- {
- com.leadpipe.attentionhog.Timer.instanceList[_loc1_].destroy();
- }
- com.leadpipe.attentionhog.Timer.instanceList = new Array();
- }
- static function pauseAll(p)
- {
- for(var _loc2_ in com.leadpipe.attentionhog.Timer.instanceList)
- {
- com.leadpipe.attentionhog.Timer.instanceList[_loc2_].pause(p);
- }
- }
- }
-