Actionscript track onmouseup outside stage, possible? - actionscript-3

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.

Related

Mouse Click vs Enter Frame Stage reference

I have a document class with some constructor code. I have two event listeners in the constructor. One of them is an enter frame listener and the other is a mouse click listener. The enter frame function moves a rectangle on the stage. The mouse event function removes it from the stage when its been clicked.
When I used the following:
addEventListener(MouseEvent.CLICK, checkTarget);
The rectangle didn't get removed. But when I used:
stage.addEventListener(MouseEvent.CLICK, checkTarget);
It worked fine. I kept the enter frame without referencing the stage and it worked.
addEventListener(Event.ENTER_FRAME,update);
Why did the mouse click need the reference to the stage and the enter frame didn't? Aren't they both added to the same thing at the same time?
mouse event needs something to work with but ENTER_FRAME is built to work with stage.
I would change the mouse event listener to listen to when you clicked at a mc just like that rectangle if I where you.

Play movie clip on click at mouse coordinates

I'm trying to play a movie clip of a circle expanding and fading away every time a user clicks. I make the movie clip, then I convert it to a movie clip again and create a motion tween making the circle get larger and fade away. But, when I call on the clip it just keeps playing over and over in the last place you click. If I set a stop at the last frame of the tween the next time you click it, it won't play.
fs15secTapBtn.addEventListener(MouseEvent.MOUSE_DOWN, fs15secdownHandler);
function fs15secdownHandler(event:MouseEvent):void
{
circletouch.x = mouseX;
circletouch.y = mouseY;
}
Thanks!
You need to start/stop the movieclip every time you click. Right now, when you click the first time the clip would be put on stage and playing. Then when you click again, all you're doing is modifying the x and y positions of the clip, which moves the clip to the mouse coords...but the clip itself would still be continuing to be in whatever state it is in during the click (playing on it's own at whatever frame).
Within your click handler add in a circletouch.gotoAndPlay(1); to restart the playing at frame 1. Also, you may want to re-add that stop(); back in so that it'll only play once.

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.

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)