/ Published in: ActionScript 3
This is a pretty robust mouse detection technique. Use the mouseIsOver variable when deciding whether to do something (ie animation)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var mouseIsOver:Boolean = false; stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoved); function mouseMoved(evt:Event):void { mouseIsOver = true; stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoved); stage.addEventListener(Event.MOUSE_LEAVE, mouseLeft); } function mouseLeft(evt:Event):void { mouseIsOver = false; stage.removeEventListener(Event.MOUSE_LEAVE, mouseLeft); stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoved); }