4 Replies Latest reply on Jul 13, 2009 9:41 PM by Sreelash

    Detecting mouse direction



                I wanna detect the direction of mouse movement. If the mouse moves tpwards the left or right of its currrent position, i want to detect it. Is there anyway to identify such movement. Actually i am implementing a 360 degree rotation of  image. That means , if the mouse moves along the left side of its current position, then the image should move along its left side, otherwise it should move along the right side. For example, view this site:  http://www.yofla.com/flash/3d-rotate/


      Regards, Sreelash

        • 1. Re: Detecting mouse direction
          Ned Murphy Adobe Community Professional & MVP

          You need to compare the previous mouse position to the current position everytime the mouse moves.  The previous position would be the current position after each adjustment.  In the examples you pointed to, when you press down (onMouseDown) with the mouse you would set the previous position and current position as the same value.  Then, when you move the mouse (onMouseMove), the difference of the previous minus current will tell you the direction the mouse moved (positive is right, negative is left).  Just after determining that you assign the previous value the current value.

          • 2. Re: Detecting mouse direction
            Sreelash Level 1

            Hi friend. Thank you very much. I could implement it. But another problem is that i want to detect when the mouse is not moving in onMouseMove event. Is there any tricks for it?




            • 3. Re: Detecting mouse direction
              Rothrock Level 5



              There is no way to detect if the mouse is NOT moving using the onMouseMove event. By definition onMouseMove only happens when the mouse is moving! There is no trick for that.


              Generally if you need to deal with that type of thing you should use an onEnterFrame or setInterval.

              • 4. Re: Detecting mouse direction
                Sreelash Level 1

                Ok freind I did it.Thank you.