2 Replies Latest reply on Aug 27, 2009 5:17 AM by Yogi_ACE

    DOUBLE_CLICK and MOUSE_DOWN on Button

    Yogi_ACE

      I am trying to utilize DOUBLE_CLICK and MOUSE_DOWN for Button control. But they both are not working together.

      Whenever I activate MOUSE_DOWN event it simply disables DOUBLE_CLICK

       

      Code:

      // _btn is my Button object

      _btn.doubleClickEnabled = true;

      _btn.addEventListener(MouseEvent.DOUBLE_CLICK, doubleClickHandler); // Handle double click event

      _btn.addEventListener(MouseEvent.MOUSE_DOWN, doDrag); // Handle mouse down for enabling drag event - Register event with DragManager

       

      But in this case only MOUSE_DOWN event gets detected. Is it the expected behaviour of Event Handler or I can handle both events?

       

      Output Expected: Both events should be handled.

        • 1. Re: DOUBLE_CLICK and MOUSE_DOWN on Button
          christopher.mina Level 1

          If you are calling a doDrag method immediately on mouse down, then focus will be removed from the button and pushed onto the dragproxy.  On mouse down, you need to defer the drag method until the user actually moves the mouse while the mouse button is down.  You might add an event listener for MouseMove and MouseUp, on the MouseDown event, and remove those listeners on MouseUp or MouseMove.  Once you hit the handler for the MouseMove event, you know the user is dragging, and not doubling clicking. 

           

          A word of advice would be to add in additional logic to look for pixel offsets prior to deciding that your user is not double clicking, but instead attempting to drag.  In this case, on mouse down you would trap the original MouseX and MouseY and store those values locally.  Then you wait until your user has moved the mouse while the button is down at least 3-5 pixels in any direction before starting the drag.  The reason is that if you only look for mouseMove, the user might have accidentally moved the mouse 1 pixel in the middle of a click (e.g. when the mouse button was actually down) and thus did not really mean to drag.

          1 person found this helpful
          • 2. Re: DOUBLE_CLICK and MOUSE_DOWN on Button
            Yogi_ACE Level 2

            Thanks buddy!

            I made it workable for a time being using MOUSE_MOVE (It is adding overhead to my application)

             

            But will try with maintaining X, Y position for sure. I guess that will work perfectly.

             

            Best Regards,

            Yogesh