6 Replies Latest reply on Jun 8, 2011 9:51 AM by Ned Murphy

    Continuous go to next/previous frame on mouseover

    Andy Bay Level 2

      Hi!

       

      I have an image sequence on my timeline in Flash.

      I also have two buttons: forwards-button and backwards-button.

       

      I would like the timeline to play constantly forward, when the mouse is held over the forwards button.

       

      And I would like the timeline to play constantly backwards when the mouse is held over the backwards button.

       

      My attempts so far have failed: I can get the button to work only for one step at a time (and then I need to bring the mouse on and off the button again for it to move to the next frame). I need to have the sequence play forwards/backwards the whole time that the mouse is over the button.

       

      How should I write that in AS3?

       

      Any help will be appreciated!

        • 1. Re: Continuous go to next/previous frame on mouseover
          Ned Murphy Adobe Community Professional & MVP

          You should show your attempts to get things working.  Overall, you should not think of the buttons as being the objects that create the movement along the timeline, they should only trigger it starting/ending and dictate which direction.  Rolling over one of the buttons could start a Timer and set a direction variable.  The Timer's event handler function would be in charge of commanding nextFrame() or prevFrame() based on the direction variables value (forward vs backward, for example) and rolling off the button would shut down the Timer.

          1 person found this helpful
          • 2. Re: Continuous go to next/previous frame on mouseover
            Andy Bay Level 2

            My attempts are too amateurish so showing them isn't useful

             

            What I don't get is why can't I simply tell a button "When the mouse is over you, proceed to next frame" and another button "When the mouse is over you, proceed to previous frame" and have that happen continuously so that as long as the mouse stays over the button, it will always proceed to the next/previous frame? Is there something in the nature of Actionscript code that makes that impossible?

            • 3. Re: Continuous go to next/previous frame on mouseover
              Ned Murphy Adobe Community Professional & MVP

              Yes, I just described it for you.  But I won't be writing it for you... it's easier (less work) for me to work with something that's already been attempted.  Someone else might though, so if you don't want to show what you've tried you can wait and see if someone else will do it for you.

              • 4. Re: Continuous go to next/previous frame on mouseover
                Andy Bay Level 2

                Okay I will post my attempts soon, but you will probably laugh as I'm very new to actionscript coding..

                • 5. Re: Continuous go to next/previous frame on mouseover
                  Andy Bay Level 2

                  Okay, here is what I have:

                   

                  button_1.addEventListener(MouseEvent.MOUSE_OVER, fl_ClickToGoToNextFrame_3);

                   

                  function fl_ClickToGoToNextFrame_3(event:MouseEvent):void
                  {
                      nextFrame();
                  }

                   

                   

                   

                  It works only for one frame at a time, in other words I have to shift my mouse on and off the button to have the movie proceed. The question I'm trying to solve is that why wont the button stay on as long as the mouse stays over it, always proceeding to a new frame?

                  • 6. Re: Continuous go to next/previous frame on mouseover
                    Ned Murphy Adobe Community Professional & MVP

                    The answer to your question is that the MOUSE_OVER event is triggered by the rolling over occuring, not from the state of being over.  So as I described ealrier, what you will want to do is have your mouseover function start a Timer and have the Timer's TIMER event handler function deal with executing the nextFrame() calls.  You could use an ENTER_FRAME event lsitener/handler instead of a Timer, but you probably want more control of how slowly the nextFrame() calls occur.