views:

2337

answers:

5

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.

+1  A: 

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.

Joel Coehoorn
All these event handlers are going on a specific UI object, so I think they'd still be meaningful. Just as meaningful as Press/Release at least.
Herms
In this case, perhaps yes. The point was that a MouseUp/Down doesn't _have to be_ meaningful, while a Press/Release probably does. The first part of my post still answers the question.
Joel Coehoorn
I'm not sure the first part is relevant. I'm not talking about buttons here, just random movie clips (canvases) in the SWF.
Herms
Absolutely this answer is relevant. Random movie clips can be "pressed" by tabbing to them and pressing the space bar, just like buttons can.
fenomas
A: 

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.

defmeta
I'm working in AS2 code, not AS3. I added a clarification to the question. Sorry, I thought I had mentioned that initially, but I guess I forgot.
Herms
+3  A: 

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.

davr
It's weird that the movie clips have an onMouseUp and onMouseDown though. That implies that they're specific to that clip, but it turns out they aren't.
Herms
You're right about Press/Release being tied to a MC, but the real difference is that these are contextually different events. That is, you can have a Press that's not a MouseDown, or a MouseDown that's not a Press. See my answer below.
fenomas
A: 

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.

Herms
+2  A: 

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).

fenomas