home *** CD-ROM | disk | FTP | other *** search
- _global.Timer = function(onChangeFunction, changeInterval, firstTick, clip)
- {
- trace("new timer");
- this.initTime = getTimer();
- this.initClip(clip);
- this.killTime = null;
- this.milissec = 0;
- this.nextChange = 0;
- this.changeInterval = changeInterval;
- this.onChangeFunction = onChangeFunction;
- if(firstTick == undefined)
- {
- firstTick = false;
- }
- this.firstTick = firstTick;
- this.dead = false;
- };
- Timer.prototype.tick = function()
- {
- this.milissec = getTimer() - this.initTime;
- };
- Timer.prototype.initClip = function(clip)
- {
- var _loc3_ = randomInt(0,1000000);
- var _loc4_ = "clock" + _loc3_;
- if(clip == undefined)
- {
- clip = "timer";
- }
- _root.attachMovie(clip,_loc4_,_loc3_);
- this.clip = _root[_loc4_];
- this.clip.obj = this;
- this.clip.onEnterFrame = function()
- {
- this.obj.enterFrame();
- };
- };
- Timer.prototype.addKill = function(num)
- {
- this.killTime = num;
- };
- Timer.prototype.kill = function()
- {
- if(this.killTime == null)
- {
- return undefined;
- }
- if(this.milissec >= this.killTime)
- {
- trace("killme");
- this.clip.removeMovieClip();
- this.dead = true;
- false;
- }
- };
- Timer.prototype.killNow = function()
- {
- trace("killme now");
- this.clip.removeMovieClip();
- this.dead = true;
- false;
- };
- Timer.prototype.change = function()
- {
- if(this.changeInterval == undefined)
- {
- this.changeInterval = 1 * SEC;
- }
- if(this.milissec >= this.nextChange || this.nextChange == undefined)
- {
- if(this.nextChange == 0 && this.firstTick == false)
- {
- this.nextChange = this.milissec + this.changeInterval;
- return false;
- }
- this.nextChange = this.milissec + this.changeInterval;
- return true;
- }
- return false;
- };
- Timer.prototype.enterFrame = function()
- {
- this.tick();
- this.kill();
- if(this.change())
- {
- this.onChangeFunction();
- }
- };
-