Skip navigation
TheEricBraun
Currently Being Moderated

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

Jun 20, 2012 1:29 PM

Tags: #help #flash #text #swf #button #buttons #as2 #play #actionscript #movieclip #actionscript_2 #game #movie #clip #2.0 #objects #movie_clip #nextframe

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

 
Replies
  • Currently Being Moderated
    Jun 20, 2012 1:43 PM   in reply to TheEricBraun
    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");
         }
    }

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 20, 2012 2:01 PM   in reply to TheEricBraun

    "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();

              }

    }

     

     


     
    |
    Mark as:
  • Currently Being Moderated
    Jun 20, 2012 2:09 PM   in reply to TheEricBraun

    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();

        }

    }

     
    |
    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