3
votes

In Flash, there seem to be two sets of mouse click events:

  • onMouseUp, onMouseDown
  • onPress, onRelease

Is there any actual difference between these events? I can't tell from the documentation, and I haven't noticed anything in actual usage, but it seems odd to have two different sets of names for the same basic events. Am I missing something? Is there a difference between them?

Clarification: This is in ActionScript 2 code, targeted at Flash 8.

5

5 Answers

5
votes

onMouseDown and onMouseUp are general events that anything can listen to via Mouse.addListener(). They get triggered no matter where the mouse is clicked.

onPress and onRelease are specific to a particular MovieClip. They only get triggered if the mouse is pressed or released while on top of that MovieClip. Also important is onReleaseOutside...for the case where you click down on a MovieClip, then drag the mouse outside, then release the mouse. In that case there will be no onRelease event, only an onReleaseOutside event, so if you're not listening to the latter, your program will think the mouse button got stuck.

4
votes

Press/Release are interaction events, not mouse events. If you activate a button or MC with the keyboard (by tabbing to it and pressing space), it will fire a Press event but not a MouseDown. Likewise, if you click on a disabled button, that will fire a MouseDown event but not a Press (since no button interaction occurs).

1
votes

Not a flash developer, but in normal windows apps you can press a button with the spacebar, and activate it via the enter key.

Also, a MouseUp/Down can happen anywhere and may not imply anything. A Press/Release on a specific control therefore has more significance.

1
votes

I found this while doing some googling of the question:

http://www.gogoat.com/2006/07/27/onpress-vs-onmousedown/

It looks like the mouseUp/mouseDown events will trigger even when the mouse is outside the movie clip, while onPress/Release will automatically check to see if the mouse is within the clip before being handled. I could have sworn I tested for that, but I just verified it, so I must not have.

-1
votes

onPress and onRelease are hold overs from AS2 code, they have been supplanted by onMouseDown and onMouseUp in AS3, which you can read about in the AS2 Migration Guide.