5 Replies Latest reply on Nov 22, 2009 2:51 PM by Rothrock

    Easing a gotoAndStop(frame) given by the mouse position

    Pedromvpg

      Hi there.

       

      I have an external swf loaded into the background and i want it to go to a frame according to the mouse vertical position.

       

      Example: when the mouse is on the bottom part of the screen the movie is in the frame 0 and when it is on the top value goes to 800.

       

      so far i did it like this:

       

       

      _root.onEnterFrame = function ()
{

           var frame:Number = Stage.height-_ymouse;

           bgContainer.gotoAndStop(frame);

           
}

       

       

      But somehow i need it to ease between the values given by the mouse position so that when there is a fast movement of the mouse, the swf only gradually goes to the frame equivalent to the last mouse position.

       

      any sugestions??

       

      Cheers!

        • 1. Re: Easing a gotoAndStop(frame) given by the mouse position
          Ned Murphy Adobe Community Professional & MVP

          What is happening in these 800 frames?

          • 2. Re: Easing a gotoAndStop(frame) given by the mouse position
            Pedromvpg Level 1

            the end of the movie.. and the end of the stage

             

            what i can not figure out is how to convert the values of _ymouse into a more smooth movement that goes though all the frames.

             

            thanks

            • 3. Re: Easing a gotoAndStop(frame) given by the mouse position
              Rothrock Level 5

              You could just apply some basic easing:

               

               

              actualFrame+=Math.round((targetFrame-currentFrame)/dampFactor);

              clip.gotoAndStop(actualFrame);

               

              Where target frame is the frame that your _ymouse position tells you that you need to get to. The current frame is the frame you are actually on. And dampFactor is a number greater than 1 (can be fractional like 1.5 or 3.2).

              • 4. Re: Easing a gotoAndStop(frame) given by the mouse position
                Pedromvpg Level 1

                actualFrame ist not a number NaN so i can't use it to define a frame to the clip to stop..



                I just need a function that makes something like this:



                _ymouse           ---->            clip.gotoAndStop()

                    

                     1                  ---->                     1

                     800              ---->                     16

                     800              ---->                     26

                     800              ---->                     67

                     800              ---->                     135

                     800              ---->                     233

                     800              ---->                     358

                     800              ---->                     498

                     800              ---->                     571

                     800              ---->                     704

                     800              ---->                     731

                     800              ---->                     800

                • 5. Re: Easing a gotoAndStop(frame) given by the mouse position
                  Rothrock Level 5

                  That is what I have given you. Not sure what you mean that actual frame is NaN. You will need to change it into your code. What I gave you isn't code, it is the algorithm/pseudo code for some generic easing. Something like this:

                   

                   

                  var frame:Number = Math.round((Stage.height -_ymouse - bgContainer_currentframe)/3);

                  bgContainer.gotoAndStop(bgContainer._currentframe+frame);