home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Diversos / beaverblast.swf / scripts / frame_1 / DoAction_2.as next >
Encoding:
Text File  |  2006-06-13  |  2.0 KB  |  90 lines

  1. _global.Timer = function(onChangeFunction, changeInterval, firstTick, clip)
  2. {
  3.    trace("new timer");
  4.    this.initTime = getTimer();
  5.    this.initClip(clip);
  6.    this.killTime = null;
  7.    this.milissec = 0;
  8.    this.nextChange = 0;
  9.    this.changeInterval = changeInterval;
  10.    this.onChangeFunction = onChangeFunction;
  11.    if(firstTick == undefined)
  12.    {
  13.       firstTick = false;
  14.    }
  15.    this.firstTick = firstTick;
  16.    this.dead = false;
  17. };
  18. Timer.prototype.tick = function()
  19. {
  20.    this.milissec = getTimer() - this.initTime;
  21. };
  22. Timer.prototype.initClip = function(clip)
  23. {
  24.    var _loc3_ = randomInt(0,1000000);
  25.    var _loc4_ = "clock" + _loc3_;
  26.    if(clip == undefined)
  27.    {
  28.       clip = "timer";
  29.    }
  30.    _root.attachMovie(clip,_loc4_,_loc3_);
  31.    this.clip = _root[_loc4_];
  32.    this.clip.obj = this;
  33.    this.clip.onEnterFrame = function()
  34.    {
  35.       this.obj.enterFrame();
  36.    };
  37. };
  38. Timer.prototype.addKill = function(num)
  39. {
  40.    this.killTime = num;
  41. };
  42. Timer.prototype.kill = function()
  43. {
  44.    if(this.killTime == null)
  45.    {
  46.       return undefined;
  47.    }
  48.    if(this.milissec >= this.killTime)
  49.    {
  50.       trace("killme");
  51.       this.clip.removeMovieClip();
  52.       this.dead = true;
  53.       false;
  54.    }
  55. };
  56. Timer.prototype.killNow = function()
  57. {
  58.    trace("killme now");
  59.    this.clip.removeMovieClip();
  60.    this.dead = true;
  61.    false;
  62. };
  63. Timer.prototype.change = function()
  64. {
  65.    if(this.changeInterval == undefined)
  66.    {
  67.       this.changeInterval = 1 * SEC;
  68.    }
  69.    if(this.milissec >= this.nextChange || this.nextChange == undefined)
  70.    {
  71.       if(this.nextChange == 0 && this.firstTick == false)
  72.       {
  73.          this.nextChange = this.milissec + this.changeInterval;
  74.          return false;
  75.       }
  76.       this.nextChange = this.milissec + this.changeInterval;
  77.       return true;
  78.    }
  79.    return false;
  80. };
  81. Timer.prototype.enterFrame = function()
  82. {
  83.    this.tick();
  84.    this.kill();
  85.    if(this.change())
  86.    {
  87.       this.onChangeFunction();
  88.    }
  89. };
  90.