Skip to main content
Known Participant
February 25, 2013
Question

How to add Score and Timer in Adobe flash

  • February 25, 2013
  • 4 replies
  • 4690 views

Hi guys I am making a android game. I am new in actionscript programming and i can't find to get this right.


I need to have a score and timer in this flash file >>> http://www.filedropper.com/eggrun


It should have coins for adding the score and a countdown timer for it's gaming time.


When the countdown timer goes to zero. The game stops then the stage will remove the game scene then a new layer will pop up with the total score in it.


Please help me guys


I am nowhere close to getting this right.

This topic has been closed for replies.

4 replies

Participating Frequently
February 25, 2013

There are many ways to do countdown timer. Here are two examples to countdown from 60 seconds to zero. Theoretically they should work the same, but practically not always. Since heavy processing can slow down frame rate and hence method #2 will not be accurate. Really depends on your need.

#1, using Timer class

var delay:Number = 1000; //the delay between timer events, in milliseconds.

var remainingTime:int = 60;

var countDownTimer:Timer = new Timer(DELAY);

countDownTimer.addEventListener(TimerEvent.TIMER, countDownUpdate);

countDownTimer.start();

function countDownUpdate(evt:TimerEvent):void{

     //1 second passed, do something

     remainingTime--;

     if(remainingTime == 0){

          //60 seconds passed, do something

          countDownTimer.stop();

          countDownTimer.removeEventListener(TimerEvent.TIMER, countDownUpdate);

     }

}

///////////////////////////////

#2, using onEnterFrame event

var frameCount:int= 0;

var remainingTime:int = 60;

addEventListener(Event.ENTER_FRAME, countDownEnterFrame);

function countDownEnterFrame(e:Event):void{

     frameCount++;

     if(frameCount == Stage.frameRate){

          //1 second passed, do something

          frameCount = 0;

          remainingTime--;

          if(remainingTime == 0){

               //60 seconds passed, do something

               countDownTimer.stop();

               countDownTimer.removeEventListener(TimerEvent.TIMER, countDownUpdate);

          }

     }

}

////////////////////////////////

As for your score part. It really depends on what exactly you're looking for. There are a lot of ways to do it, and for each way to do it there are even more methods to implement it. Maybe you can try to describe in more details of what you have in mind, so people can help you easier. Don't worry if one method doesn't work for you, since there are so many ways to do things in Flash with AS3. Good luck

Known Participant
February 26, 2013

look at this >>> http://www.filedropper.com/test_37. CS5

I now have some coins for the score, and the score is now adding up..

I also have the countdown timer, but the timer doesn't stop at 0 it still goes on. It goes on to negative numbers (-1, -2, and so on...)

Please help me fix it guys..

Participating Frequently
February 26, 2013

I'm assuming your "count" variable is used to keep track of score. So your

     var myTimer:Timer = new Timer(1000, count);

should be,

     var myTimer:Timer = new Timer(1000, time);

One advice, try to avoid using special reserved words for your variables. Since the uncertainty of compilers is not always predictable. For example,

     function countdown(event:TimerEvent):void{}

Would be safer if it's written as,

     function countdown(evt:TimerEvent):void{}

Or even,

     function countdown(e:TimerEvent):void{}

Since the word "event" is a reserved word in AS3, it could behave differently if used in special situations. These reserved words usually show up in a special color in Flash Pro or other AS3 specific editor.