home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Aventura / VenusMission.swf / scripts / __Packages / games / Score.as < prev   
Encoding:
Text File  |  2008-09-23  |  1.8 KB  |  60 lines

  1. class games.Score
  2. {
  3.    var scoreMC;
  4.    var game;
  5.    var timer;
  6.    var _addString;
  7.    var _stepdisplay;
  8.    var _newScoreValue = 0;
  9.    function Score(instance, MC, depth)
  10.    {
  11.       this.scoreMC = MC;
  12.       this.scoreMC.swapDepths(depth);
  13.       this.game = instance;
  14.       this.timer = system.Timer.getInstance(this.scoreMC);
  15.       this._addString = this.game.score_addString;
  16.       this._stepdisplay = this.game.score_stepdisplay;
  17.       this.scoreMC.scorefield.score = "0";
  18.    }
  19.    function resetTo(val)
  20.    {
  21.       this._newScoreValue = Number(val);
  22.       this.scoreMC.scorefield.score = val;
  23.       this.updateScore();
  24.    }
  25.    function getValue()
  26.    {
  27.       return this._newScoreValue;
  28.    }
  29.    function setValue(scoreValue)
  30.    {
  31.       var displayedscore = Number(this.scoreMC.scorefield.score);
  32.       var newdisplay = Number(scoreValue + this._addString);
  33.       if(scoreValue == "")
  34.       {
  35.          this.scoreMC.scorefield.score = "0";
  36.       }
  37.       else if(isNaN(scoreValue) || isNaN(displayedscore))
  38.       {
  39.          this.scoreMC.scorefield.score = newdisplay;
  40.          this.timer.removeListener(this.scoreMC);
  41.       }
  42.       else if(displayedscore < newdisplay)
  43.       {
  44.          this._newScoreValue = newdisplay;
  45.          this.timer.addListener(this.scoreMC,0,system.Delegate.create(this,this.updateScore));
  46.       }
  47.    }
  48.    function updateScore()
  49.    {
  50.       var TF = this.scoreMC.scorefield;
  51.       var displayedscore = Number(TF.score);
  52.       var addvaltodisplay = (this._newScoreValue - displayedscore) / this._stepdisplay;
  53.       TF.score = displayedscore + (addvaltodisplay <= 0 ? Math.floor(addvaltodisplay) : Math.ceil(addvaltodisplay));
  54.       if(addvaltodisplay == 0)
  55.       {
  56.          this.timer.removeListener(this.scoreMC);
  57.       }
  58.    }
  59. }
  60.