4 Replies Latest reply on Jun 1, 2013 7:01 AM by kglad

    AS2 Game Timer


      Hey, basically I'm having real trouble with the timer in my game;

      I have a countdown timer with the code:


      timer = 30;



      countdown = function(){ timer--; if(timer==0){








      countdownInterval = setInterval(countdown,1000);


      Now this counts down fine though doesn't get me to the correct frame when it runs it get to 0, just goes to a blank frame. I may also note that the timer is inside a vcam layer so that it follows the character at the same time. So how would I get the timer to go to the correct frame when finished? Also the more important point, I have some collectables in my game that when you hit them I want it to pause the timer for a select amount of time. This is on the main games' layer. Now I'm unsure of this code and could really do with some help knowing how to do it since I've tried loads of different pieces.


      Help would be much appriecated


      *Edit: also I'm using this code to pick up the collectables which seems to work well except for adding or pausing time on the timer:







        • 1. Re: AS2 Game Timer
          kglad Adobe Community Professional & MVP

          if that code is causing the _root timeline to go to the wrong frame, it's because either _root isn't what you think it is or you have no single "GameOver" frame label on your _root timeline.  (use Movie Explorer to check your frame labels.)


          to pause your timer, use:




          to restart your timer, use:


          countdownInterval = setInterval(countdown,1000);

          • 2. Re: AS2 Game Timer

            try it:




            function timer()








            (timer, 1000);

            • 3. Re: AS2 Game Timer
              CamHeadZoo Level 1

              I've tried looking at my frame labels and they seem correct. When I take the _root from it the timer just stays at 0 and doesn't move to another frame. Also how would I use the:




              on one of the collectables because I don't think I'm using the actionscript correctly it will pick up the collectable but the timer just carries on...



              • 4. Re: AS2 Game Timer
                kglad Adobe Community Professional & MVP

                you just need to execute:




                when you pick up an object.  you must have some kind of loop that probably checks a hittest between your character and the objects.  that's where you would add the clearInterval.


                attach a screenshot showing your frame label (in the properties panel).


                also, if you have more than one scene, make sure you're not testing scenes (test movie) when you test that goto/

                1 person found this helpful