AS3 cancel event - actionscript-3

Hey so I have an MC with multiple buttons in it, I can drag the container MC, when I release the MC I want to cancel any MouseEvent.CLICK listeners that may have fired during. mouseEnabled and mouseChildren is not an option for my current problem, thanks.

Can you use an option to intercept events of container from travelling to child while dragging?
Add listener to container, and stop propagation on those events, using capture phase.

Related

Actionscript track onmouseup outside stage, possible?

So I'm working on a button that plays a sound when clicked or 'mousedown' on, and stops playing when releasing the mousebutton. The mouseup event is set on the stage object.
So the issue is when the cursor is dragged outside the flash movie and then released, the sound doesn't stop since the onmouseup doesn't register anymore.
Thus is there a way to detect either mouseup events, or mouse coordinates outside the stage/flash object itself with actionscript?
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Stage.html#event:mouseLeave
Add an Event.MOUSE_LEAVE listener to the Stage. This event fires in 2 ways:
Mouse button is already released and leaves the Stage
Mouse button is down and leaves the Stage, then mouse button is released
If your mouse button is down and you leave the Stage, it doesn't fire. An example reason is this: You start dragging a MovieClip and you go off Stage, when you come back to the Stage naturally you expect to still be dragging.

Multiple mouse event as3

I got a MovieClip that is listening to mouse over and out events.
Inside this movie clip I want to show a button when mouse over.
The problem is that movie clip gets the mouse out event when moving to the button area.
I want him to get mouse out event only when living his rect area.
I found one solution: to make mouse position calculation and compare them to my movieClip position to detect if I should handle or ignore the event.
But is there more simple, more Adobe solution?
Edit: The inner button need to receive mouse events as well
set mouseChildren = false for your MovieClip or use ROLL_OVER and ROLL_OUT, here's a great article on the subject
ROLL_OVER and ROLL_OUT events should work (use them instead of MOUSE_OVER and MOUSE_OUT).
Does the inner button need to receive MouseEvents as well? If not, just set it's
button.mouseEnabled = false;
or you can set the parent movie clip's
movieclip.mouseChildren = false;

AS3 - Detect if mouse is down, even if overlaps

I would like to know if the mouse button is down, even if another object is being clicked. How do I do that? Simply adding event listeners doesn't work as it does not trigger if something else is on top of the object.
Thanks
Add both a Click & MouseDown event listeners to the stage.
If an object is clicked , the event will bubble up to the stage so you should be able to register it and react accordingly.
You can also check the event.currentTarget property to find out where the event originated from , this should tell you if it was the stage or an object being clicked as well as where the mouse down event came from.
Add a mouse down event listener to the stage (or other parent of all objects in question)

Behavior of MOUSE_OVER eventListener in action-script-3

If the mouse is over an object before and while a MOUSE_OVER event is registered, does it trigger? I ask this because it appears that it doesn't in my program, and I want to know if this is a universal behavior of all MOUSE_OVER events. Is there a way around this?
I'm gonna avoid giving a code example here, because my program is large and complicated.
The MOUSE_OVER event will dispatch whenever the cursor enters the bounds of any interactive DisplayObject, such as a Sprite or MovieClip; this includes any of its children (see ROLL_OVER if you wish to ignore children).
As well, the event will dispatch in cases where an object is added to the stage and currently happens to be under the cursor.
It is important to make sure that your event listener has been registered before the Flash Player has dispatched the event -- system events are not queued beyond a single frame, and thus no handlers will be invoked for previous activity.

Listen to click event on overlapped sprites

I have two sprites in my movieclip, one under the other, and i want both to listen to mouse clicks event.
I found that only the top level sprite receives the event when i click on it.
I need to dispatch the events on both, so I can't use mouseenabled=false.
Is there a simple workaround for this?
Another solution is, that you listen to the click-event on the upper sprite, and fire it again with
dispatchEvent(new MousEvent(event));
Have a look at the "bubble" property of the event.
You can use the 'getObjectsUnderPoint' method native to the DisplayObjectContainer
You can see how it works here:
http://snipplr.com/view/34945/as3-trace-movieclips-under-mouse/
and the AS3 reference here:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html
You would listen on the stage for any click event and if one occurs, check to see if the element you require is under that click position.