1

I have a scenario where I am listening to both CLICK and MouseDown events for an object.

On MouseDown I do a startDrag(). And on Click, I perform something else.

But the problem is that, MouseDown event fires first and it initiates a drag. The click event does not fire. How do I solve this issue?

Jason Towne
  • 8,014
  • 5
  • 54
  • 69
Ranhiru Jude Cooray
  • 19,542
  • 20
  • 83
  • 128

1 Answers1

2

You can listen MouseDown event and when it fires subscribe MouseMove and MouseUp events and remember coordinates of cursor on MouseDown. Then determine a delta (say 1px) which will be a sign of starting dragging. So if MouseMove invokes you check current mouse position and determine if user is really dragging (using your delta). In this case invoke startDrag(). In other case Click event will be invoked.

And remember unsubscribing events! :)

Constantiner
  • 14,231
  • 4
  • 27
  • 34
  • This is the way to do it. I posted some code you might find useful in an answer to another question. http://stackoverflow.com/questions/1563434/detect-mouse-leave-stage-while-dragging-in-actionscript-3/1691635#1691635 – Ryan Lynch Apr 18 '11 at 13:13