home *** CD-ROM | disk | FTP | other *** search
- class games.Score
- {
- var scoreMC;
- var game;
- var timer;
- var _addString;
- var _stepdisplay;
- var _newScoreValue = 0;
- function Score(instance, MC, depth)
- {
- this.scoreMC = MC;
- this.scoreMC.swapDepths(depth);
- this.game = instance;
- this.timer = system.Timer.getInstance(this.scoreMC);
- this._addString = this.game.score_addString;
- this._stepdisplay = this.game.score_stepdisplay;
- this.scoreMC.scorefield.score = "0";
- }
- function resetTo(val)
- {
- this._newScoreValue = Number(val);
- this.scoreMC.scorefield.score = val;
- this.updateScore();
- }
- function getValue()
- {
- return this._newScoreValue;
- }
- function setValue(scoreValue)
- {
- var displayedscore = Number(this.scoreMC.scorefield.score);
- var newdisplay = Number(scoreValue + this._addString);
- if(scoreValue == "")
- {
- this.scoreMC.scorefield.score = "0";
- }
- else if(isNaN(scoreValue) || isNaN(displayedscore))
- {
- this.scoreMC.scorefield.score = newdisplay;
- this.timer.removeListener(this.scoreMC);
- }
- else if(displayedscore < newdisplay)
- {
- this._newScoreValue = newdisplay;
- this.timer.addListener(this.scoreMC,0,system.Delegate.create(this,this.updateScore));
- }
- }
- function updateScore()
- {
- var TF = this.scoreMC.scorefield;
- var displayedscore = Number(TF.score);
- var addvaltodisplay = (this._newScoreValue - displayedscore) / this._stepdisplay;
- TF.score = displayedscore + (addvaltodisplay <= 0 ? Math.floor(addvaltodisplay) : Math.ceil(addvaltodisplay));
- if(addvaltodisplay == 0)
- {
- this.timer.removeListener(this.scoreMC);
- }
- }
- }
-