3 Replies Latest reply on May 23, 2011 4:55 AM by Ned Murphy

    gotoAndPlay closure?

    danlinenberg10

      Hey,

      i have a character, and i've added 3 animations to it in the timeline. i want to make it go to every animation when i click it, and in the third one, i want to to go back to the first animation, and then go back to the second, third, and repeat indefinetly. problem is, once it gets to the third animation, it keeps repeating it....

      how do i make it do that?

       

      here's the code i wrote-

       

      first animation -

      stop();

       

      ninja_mc.addEventListener(MouseEvent.CLICK, charMoveTwo);

       

      function charMoveTwo(evt:MouseEvent):void {

      gotoAndPlay(13);

      }

       

       

      second animation-

      stop();

       

      ninja_mc.addEventListener(MouseEvent.CLICK, charMoveThree);

      function charMoveThree(evt:MouseEvent):void {

      gotoAndPlay(23);

      }

       

      third animation -

      stop();

       

      ninja_mc.addEventListener(MouseEvent.CLICK, charMoveFinal);

       

      function charMoveFinal(evt:MouseEvent):void {

      gotoAndPlay(1);

      }

       

       

      at this point the clip just replays the third animation, and doesnt actually go back to the first frame...I need it to go to that code of that frame too, not only to the frame itself.

        • 1. Re: gotoAndPlay closure?
          Ned Murphy Adobe Community Professional & MVP

          What might be happening is you are piling up the event listeners on the ninja_mc such that the last one applied remains as the dominant one.  One of two things to try...  Either remove the event listener each time, or use the same listener/function for all

           

          1) Removing the listener

           

          ninja_mc.addEventListener(MouseEvent.CLICK, charMoveTwo);

           

          function charMoveTwo(evt:MouseEvent):void {

               gotoAndPlay(13);

               ninja_mc.removeEventListener(MouseEvent.CLICK, charMoveTwo);

          }

           

           

          2A) Using the same function (with variable for frame)

           

          Use a variable that you set to a frame value when you land in a particular frame.  THe listener and function are only defined in frame 1, the variable gets reassignewd a new value as you move to diferent parts of the timeline.

           

          // frame 1 code

          var nextframe = 13;

           

          ninja_mc.addEventListener(MouseEvent.CLICK, charMove);

           

          function charMove(evt:MouseEvent):void {

               gotoAndPlay(nextframe);

          }

           

          ----------

           

          // assigned in frame 13

          nextframe = 23;

           

          ----------

           

          // assigned in frame 23

          nextframe = 1;

           

           

          2B)  Using same function relying on stop() commands... just have stop() commands where you want to stop in the timeline

           

          ninja_mc.addEventListener(MouseEvent.CLICK, charMove);

           

          function charMove(evt:MouseEvent):void {

               play();

          }

          1 person found this helpful
          • 2. Re: gotoAndPlay closure?
            danlinenberg10 Level 1

            the nextframe thing is a good idea but for some reason it doesnt work after the third actionscript keyframe...

            i have really no idea why, everything is in place...

            this is how it looks flashy.jpg

            • 3. Re: gotoAndPlay closure?
              Ned Murphy Adobe Community Professional & MVP

              Since there are no gaps in the timeline the last one offered would probably be the easiest to manage, though all three are good ideas.  The fewer active listeners you have at one time, the better.