Skip navigation
Currently Being Moderated

How to add Score and Timer in Adobe flash

Feb 25, 2013 2:41 AM

Tags: #as3 #android #cs6

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.

 
Replies
  • Currently Being Moderated
    Feb 25, 2013 9:14 AM   in reply to juliuz0001

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2013 10:41 PM   in reply to juliuz0001

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points