Monday, September 10, 2007
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;
}
4 Comments:
-
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).” -
e.dolecki said...
-
“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 ;)”
-
senocular said...
-
“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).
:)”









