The cursor has left the Stage, or has it?
A reader asked me if there is a reliable way to determine if the mouse cursor has left the Stage in Actionscript 2. I believe the best approach is to use Javascript to see which object in the DOM has the mouse over it. But it would be nice if there were a reliable way to do it in Actionscript.
Here’s what I came up with which amounts to zero:
- There are no Stage events to listen to so that doesn’t help.
- Checking the _xmouse, _ymouse on an interval doesn’t really help because the last position of the mouse cursor is reported when the cursor leaves the Stage.
- Creating a large MovieClip to cover the Stage and listening for onRollOut on it won’t help because any MovieClips above it will trigger the onRollOut when you rollOver another MovieClip.
It’s rather simple to do with Actionscript 3 but that isn’t an option for my friend.
[ download code ]
package {
import flash.display.Sprite;
import flash.events.Event;
public class MouseOverStage extends Sprite {
public function MouseOverStage() {
stage.addEventListener( Event.MOUSE_LEAVE, mouseOutHandler );
}
private function mouseOutHandler( event:Event ):void {
trace( "mouse has left the stage" );
}
}
}
Anyone have a suggestion?
If something here has proved valuable to you then feel free to drop a couple of bucks in the tip-jar.






