MouseEvent.CLICK vs. MouseEvent. MOUSE_UP

Though it may seem obvious, you may want to be wary of using both MouseEvent.CLICK and MouseEvent.MOUSE_UP on the same display object in Flash using ActionScript 3.0.

Basically what happens is the function assigned to MouseEvent.CLICK may not always register (as it would be desired). My unscientific guess is that it's because the CLICK and MOUSE_UP events happen so closely together.

I ran into an issue where I added a function to a button's CLICK listener after the fact that it had already had a function assigned to its MOUSE_UP listener. Of course, as explained above, the CLICK function didn't always register when the button was clicked. This entailed much hair pulling and scratching of eyebrow. Both, in fact. Yet, happily, after much trial and error, I finally narrowed it down to this.

During the lengthy debugging process, I wondered, what really is the technical difference between the two, however, at the moment, Googling the difference between CLICK and MOUSE_UP* doesn't really provide much clarification, and of course, Adobe's official help docs are, well, not very helpful in this particular case.

I did, however, manage to find a comment that mentioned CLICK only "fires when [a] button goes to down state and then goes back to up state" -- so I assume that MOUSE_UP only fires off (immediately) when the mouse button is pressed down.

[ UPDATE: April 19, 2009 ]

*Actually, good news: as of today's writing, a new Google search on the difference between CLICK and MOUSE_UP yields a pretty clear-cut answer:

(from cessnajumpin on the FlashKit forums)

MOUSE_UP is fired only when the mouse button is released. MOUSE_CLICK needs to have both the mouse being pressed and mouse being released to be fired.

There are cases when you need to be able to distinguish between the two. I recently made a site where the user could click and drag photos all around the stage (Using MOUSE_DOWN to startDrag, and MOUSE_UP to stop), but if they were clicked then a menu would open for that photo.


About this entry