开发者

How to handle both CLICK and MouseDown events in Flex?

开发者 https://www.devze.com 2023-02-25 08:16 出处:网络
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.

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 开发者_如何学Godoes not fire. How do I solve this issue?


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! :)

0

精彩评论

暂无评论...
验证码 换一张
取 消