Some favorite site feeds aggregated locally: iPhone Development RSS   Adobe Labs RSS   Macrumors RSS

Monday, September 10, 2007

MOUSE_LEAVE annoyance

Monday, September 10, 2007   

AS3 gives us the MOUSE_LEAVE event when listened for, and its really quite handy and something we have been clamoring for as developers for a long while. However, it does not respond if you perform a mouse press & drag outside the stage (until the mouse comes back up). So it would seem like the event is really a MOUSE_UP when the mouse it outside the bounds of the stage. You can take care of your UI stuff at that point, but I wish we could get this even regardless of whether the mouse was down or not.
import flash.events.MouseEvent;
import flash.events.Event;
import flash.ui.Mouse;

stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
stage.addEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler);

function mouseMoveHandler(event:MouseEvent):void{
Mouse.hide();
cursor.visible = true;
cursor.x = stage.mouseX;
cursor.y = stage.mouseY;
}

function mouseLeaveHandler(event:Event):void{
Mouse.show();
cursor.visible = false;
}
 
 Return to the main page
Comments:

There are currently 5 Comments:

Anonymous Tony Fendall said...
“Sounds to me like you're looking for MouseEvent.MOUSE_OUT

This one does what you're looking for, but I have found a small bug where the event doesn't fire is the user is moving their mouse slowly (less than 10px per second or so).”
 
Blogger e.dolecki said...
September 10, 2007 5:24 PM
“so have the stage look for a MOUSE_OUT? i thought the point of MOUSE_LEAVE was to fire an event when the mouse... leaves ;)”
 
Blogger senocular said...
September 10, 2007 6:45 PM
“Continuing mouse detection out of the player is a very useful feature for the player, especially when interacting with dragged content (MOUSE_DOWN + MOUSE_MOVE). The MOUSE_LEAVE event is more of a detector for when mouse interaction is lost. That happens when not "dragging" and the mouse leaves the player. If you need to check to see when the mouse leaves the bounds of the player absolutely, you can check MOUSE_LEAVE in combination with MOUSE_MOVE (which is also normally used to determine when the mouse has returned) and simply check to see if the mouse is within (0,0 x stageWidth,stageHeight).
:)”
 
Anonymous arayh said...
December 5, 2007 2:19 AM
“@senocular

Unfortunately, it appears that MOUSE_MOVE is never triggered while the cursor is outside the flash player.. only to make us wonder why mouse interaction is only "semi-lost"..”
 
OpenID jimisaacs said...
June 8, 2009 12:44 AM
“There's a lot of old posts about this topic floating around and I am just linking to a post I wrote on the subject.

http://ji.dd.jimisaacs.com/archives/762

This is just so I don't leave a 10 mile long comment on these old posts ;)”
 
 Leave a comment