5 Replies Latest reply on Jun 20, 2012 2:09 PM by esdebon

    Once a timer is at 40 go to the next frame.

    TheEricBraun Level 1

      Hey there,

       

      When a timer in my game hits 40 I want it to go to the next frame. Here is what I have:

       

       

       

      onClipEvent (enterFrame) {
                var atFrame:Boolean = false;
      
      
                if (_root.timer == 40) {
                          atFrame = true;
      
      
                } else {
                          _root.timer++;
                }
      
      
                if (atFrame == true) {
                          myRandom = random(3);
                          if (myRandom == 0) {
                                    gotoAndStop("game1");
                          }
                          if (myRandom == 1) {
                                    gotoAndStop("game2");
                          }
                          if (myRandom == 2) {
                                    gotoAndStop("game3");
                          }
                }
      }
      
      

       

      Where "game1-3" are the names of my frames. And timer is the name of my dynamicText.

       

      Any suggestions as to why this isn't working would be greatly appreciated.

       

      Kind Regards, Eric

        • 1. Re: Once a timer is at 40 go to the next frame.
          esdebon Level 4
          first of all your variable must be initiated
          _root.timer=0
          Yor code is insede a MovieClip?

          I change the code

           

           

          _root.timer = 0;


          onClipEvent (enterFrame) {
                    var atFrame:Boolean = false;

                    if (++_root.timer == 40) {
                             
          goGame();
                    }

          }

           

          function goGame() {
               myRandom = int(Math.random()*3);
                if (myRandom == 0) {
                    _root.gotoAndStop("game1");
               }
               if (myRandom == 1) {
                   
          _root.gotoAndStop("game2");
               }
               if (myRandom == 2) {
                   
          _root.gotoAndStop("game3");
               }
          }

          • 2. Re: Once a timer is at 40 go to the next frame.
            TheEricBraun Level 1

            That did clean up my code, although it seems to be doing the same thing, timer just keeps increasing and the frame doesn't change :/

            • 3. Re: Once a timer is at 40 go to the next frame.
              esdebon Level 4

              "game1","game2","game3" are the label in the time line or the name of the frames inside the movieclip?

               

               

              try this

               

               

              code in the time line:

               

               

              _root.timer = 0;

              stop();

               

              function goGame() {

                   myRandom = int(Math.random()*3);

                    if (myRandom == 0) {

                        gotoAndStop("game1");

                   }

                   if (myRandom == 1) {

                        gotoAndStop("game2");

                   }

                   if (myRandom == 2) {

                        gotoAndStop("game3");

                   }

              }

               

               

              code in the moveclip

               

              onClipEvent (enterFrame) {

                        var atFrame:Boolean = false;

                        if (int(++_root.timer) == int(40)) {

                                  _parent.goGame();

                        }

              }

               

               


              • 4. Re: Once a timer is at 40 go to the next frame.
                TheEricBraun Level 1

                Thank you very much

                • 5. Re: Once a timer is at 40 go to the next frame.
                  esdebon Level 4

                  you´re welcome

                   

                   

                  is too a solution

                   

                  onClipEvent (load) {

                      function goGame() {

                          myRandom = int(Math.random()*3);

                          if (myRandom == 0) {

                              gotoAndStop("game1"); //for frame inside the movieclip or _parent.gotoAndStop("game1");

                          }

                          if (myRandom == 1) {

                              gotoAndStop("game2"); //for frame inside the movieclip or _parent.gotoAndStop("game2");

                          }

                          if (myRandom == 2) {

                              gotoAndStop("game3"); //for frame inside the movieclip or _parent.gotoAndStop("game3");

                          }

                      }

                  }

                   

                   

                  onClipEvent (enterFrame) {

                      var atFrame:Boolean = false;

                      if (++_root.timer==40) {

                          goGame();

                      }

                  }