Multiple mouse event as3 - actionscript-3

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;

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.

Custom cursor issue with nested movieclips

I made a custom cursor and add mouse event listeners to it, so it can animate according to mouse clicks (Up/Down) and also hide after 4 seconds if the user didn't click or move the mouse.
The custom cursor was working OK, but after loading external SWF to the container I found that custom cursor event listeners is not working with all movie clips on the child SWF (external loaded SWF). So It is not animating with mouse events and not resetting hide timer, which causing mouse to hide even if the user are moving or clicking it.
The hierarchy of movie clips as follows:
-- Scene 1
-- container's Buttons and controls MCs
-- myLoader content //added under the controls MC
-- content_mc //contains the child movie clips
-- child's movie clips //contains animations and simple buttons
I tried to set
myLoader.mouseChildren = false;
This solves the custom cursor issue but also blocked all mouse events on the child SWF and make all child's buttons unclickable.
So, I wonder if you can help me finding a way to make the custom cursor events working with the nested movie clips without blocking the nested movie clips mouse events.
You should find that if you place the listener at the top level class and set capture to true you should get all the events you need

AS3 cancel event

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.

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)

'glasspane' for as3 to intercept events to everything on stage?

Is there something like the java 'glasspane' in as3?
The glass pane is useful when you want to be able to catch events or paint over an area that already contains one or more components. For example, you can deactivate mouse events for a multi-component region by having the glass pane intercept the events. Or you can display an image over multiple components using the glass pane. http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html
Why do this? While some animations are underway in flash, I want to prevent any mouseevents from firing. I could remove all listeners systematically, then re-add them after the animation, but if there is something like a glasspane, it might be an easier way to achieve the same effect.
My current thinking is to:
add a sprite to the stage
stretch to width and height of the stage,
give the sprite the highest z-order,
grab all events on this sprite, and stop their propagation?
if you set
enabled=false;
mouseChildren=false;
on to the top most DisplayObject it should disable all mouse events for your app. I've used it and it works a treat.
For a more specific approach, e.g. only block clicks but let mouse down etc. through I use this approach. It uses a 'clickBlocker' stage event handler during capture phase, stopping propagation to any other object.
public function blockClicks():void{
if(!stage) return;
stage.addEventListener(MouseEvent.CLICK, clickBlocker, true); //useCapture!
}
private function clickBlocker(event:MouseEvent):void{
trace("Me (the stage) gets the "+event.type+" first, and I block it #"+event.stageX+"/"+event.stageY);
event.stopImmediatePropagation();
}