2 Replies Latest reply on Feb 3, 2010 12:07 AM by magortdsfg

    Trouble with timeline frames

    magortdsfg

      Hi,

       

      I have a timeline with 20 frames and an image in each of them.


      I added a button to step one frame forward for each time I click (mouse up) the button.

       

      But when I have stepped through all 20 frames for the first time and start a new "round" at frame 1 again, it seems like I get two steps (frames) forward instead of one as a result. And this accelerates to three three forward instead of one on the third "round". Can someone please help me to see the logical problem?

       

      This is my code:

       

      btn_forward.addEventListener(
        MouseEvent.MOUSE_UP,
        function(evt:MouseEvent):void {
          
          if (currentFrame == totalFrames)
          {
              trace(currentFrame);
              gotoAndStop(1);
             
          }
          else
          {
              trace(currentFrame);
              gotoAndStop(currentFrame + 1);
          }
        }
      );

       

       

      When I trace currentFrame on the first "round" I get this result:

      First click:

      1

       

      Second click:

      2

       

      Third click:

      3

       

      And so on..

       

       

      And when I trace currentFrame in the following (second) "round" I get this result:

      First click:

      1

      2

       

      Second click:

      3

      4

       

      Third click:

      5

      6

       

      And so on..

       

       

      Any ideas?

        • 1. Re: Trouble with timeline frames
          kglad Adobe Community Professional & MVP

          you must add your event listener exactly once.  when you add it a 2nd time, you have two listeners etc.:

           

          var listenerAdded:Boolean

           

          if(!listenerAdded){

           

          listenerAdded=true;

           

          btn_forward.addEventListener(
            MouseEvent.MOUSE_UP,
            function(evt:MouseEvent):void {
              
              if (currentFrame == totalFrames)
              {
                  trace(currentFrame);
                  gotoAndStop(1);
                 
              }
              else
              {
                  trace(currentFrame);
                  gotoAndStop(currentFrame + 1);
              }
            }
          );

          }

           

           


          • 2. Re: Trouble with timeline frames
            magortdsfg Level 1

            Great, thanks!