Move mouse out of bounds Actionscript 3 - actionscript-3

My problem is really simple
I´ve an artifact with a mouse inside. When you use it it simulates moving the mouse cursor indefinitely to the right.
Of course when i run my project at some point the mouse will reach the right side of the movieclip and the Mouse_Move event wont work anymore
I need a way make my actionscript to recongnise mouse movement even if im out of bounds
(It´s a mobile aplication so using full screen wont work)
In other words i need a Mouse-Motion Listener!

Though it is not possible to track mouse movements outside of flash with only ActionScript, you could capture the mouse position with javascript in the browser and pass it to your SWF.
See this blog as an example. http://www.nelsond8.com/?p=515

You cannot track the mouse position or actions when it moves outside of the stage.
You can however track when the mouse actually leaves the stage using Event.MOUSE_LEAVE:
function mouseLeave(e:Event):void
{
trace("Mouse left the stage.");
}
stage.addEventListener(Event.MOUSE_LEAVE, mouseLeave);
From here you can decide what the most appropriate course of action will be for your application - adding some 'pause' functionality is pretty common.
Tip: MouseEvent.MOUSE_MOVE is what you should use to detect when the mouse re-enters the stage.

Related

Is it possible to make an object "Transparent" to mouse click?

Im developing a flash game, and i would love to implement raining effect. Here's my progress on rain so far: http://www.squ4re.eu/Rain.html
The code is pretty simple; every raindrop is an object, when it hits the ground it places itself again at the top of the screen and adds splash animation.
But the problem is to click something BEHIND the rain. Lets say i have some selectable units at the battleground. In most cases an random raindrop interrupts selecting an object behind it. So here's my question: Is it possible in flash to create object "transparent" to mouse click, so i can click an object behind it? Or is there any other way to solve this problem?
Thank you in advance.
As #putvande mentioned, you could use mouseEnabled on every interactive object that should be disabled for mouse interaction. You also could create rainLayer and disable it for mouse interaction:
myRainLayer.mouseEnabled = false;
myRainLayer.mouseChildren = false;
mouseChildren - determines whether or not the children of the object are mouse, or user input device, enabled. If an object is enabled, a user can interact with it by using a mouse or user input device. The default is true.
Also consider to use display objects that don't inherit from InteractiveObject, like Bitmap, Shape and Video

Flash Expandable Banner - Detect Mouse Leave

I have created an expandable banner ad in Flash. Everything is great except one thing. How can I detect when the user is no longer hovering over the flash ad? I have tried to ad a "hit area" which can be used to detect MOUSE_OUT. The issue is, there is a video playing, as well as social media buttons which need to be clickable. If I place a hit area over these, they are no longer clickable. If I place the hit area behind the buttons, the MOUSE_OUT event triggers when you hover over the button.
What is the best practice for a scenario such as this? I have also tried detecting MOUSE_LEAVE on the stage object, but this doesn't seem to function correctly once deployed on an HTML page. Thanks for the assistance.
You can try adding an ENTER_FRAME event that constantly checks stage.mouseX and stage.mouseY. These values should report correctly while the mouse is on the Flash content, and will report the last known mouse coordinates when the mouse is no longer on the stage. However, the last known mouse coordinates may not always be the actual width or height of the stage, so you probably want to add some tolerance in there.
For instance, if your (expanded) Flash content width is 500px, in the ENTER_FRAME event you can check if stage.mouseX is less than 10px (mouse moving off to the left) or more than 490px (mouse is moving off to the right) and minimize the Flash content. Repeat for the height, and adjust tolerance values as needed.
This should give you the effect you want. The only downside that I can see is the overhead of the ENTER_FRAME event just to check whether the mouse has left the content, but I don't see any way around that.

MOUSE_OUT outside of a movieclip?

I'm having a little problem here,
I'm new to Actionscript 3, and what I'm trying to do is build a navigation menu.
What I did is I made a movieclip, added two listeners to it, MOUSE_OVER, and MOUSE_OUT,
the MOUSE_OVER tells the menu to play, so it then animates the opening of it,
the problem though, that when I put my mouse on the buttons themselves, the menu thinks that the mouse is out of it,
I understand that the mouse left the menu itself and entered some other object,
I thought of making a new rectangle, and on the mouse out, to check whether the mouse is really out of the menu's regions, it didn't work though,
I'd be glad to know how to do that,
thanks in advance
You should use the MouseEvent.ROLL_OUT event which fires only if you your mouse is out of the clip and all its children whereas MOUSE_OUT only considers the clip itself.

Redirecting Swing mouse events

I am trying to make it possible to display and interact with Java Swing components on top of a Java3D canvas. I am displaying the components by painting a transparent JPanel to a buffered image, and then painting that buffer over the canvas using J3DGraphics2D.
What I can't figure out is how to forward mouse events to the swing components in the JPanel.
I want all keyboard and mouse events on the Canvas3D to be dispatched to the JPanel, and then fall back through to the Canvas3D if they aren't captured by any swing components (e.g. the mouse isn't over any of them).
I tried calling Container.dispatchEvent(AWTEvent), but it doesn't successfully dispatch the events to the proper components, even when for example the mouse cursor is right over a button in the Container.
Does anyone know a way to do this? It should be possible.
At long last, I figured it out! It's already been done -- use JCanvas3D and a JLayeredPane. This is the opposite approach to rendering the Swing components in postRender()-- JCanvas3D renders into an offscreen buffer, and then paints to the screen with AWT, creating a lightweight canvas that interacts properly with components in the JLayeredPane, even if they are transparent.
One thing to watch out for -- JCanvas3D redirects all input to the offscreen Canvas3D, but at first my Orbiter didn't work like it had with a heavyweight Canvas3D. All you have to do is add mouse & key listeners to the JCanvas3D, because AWT won't even deliver those events if there are no listeners registered for them.

'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();
}