AS2 Detecting When Mouse Leaves the Stage
by Alan
A handy script when working with Actionscript 2 code. Because there is no Actionscript 3 Event.MOUSE_LEAVE equivalent in AS2. the best thing to do is to write a custom script for mouse detection on stage. I don’t know who authored this, but I’d like to record it so it doesn’t get lost on the internet.
var mouse_dx:Number=_xmouse; var mouse_dy:Number=_ymouse; var mouseSpeed:Number=1; function checkPosition(Void):Void { if(_xmouse(Stage.width-mouseSpeed) || _ymouse(Stage.height-mouseSpeed)) { in_mc._visible=false; out_mc._visible=true; trace("out"); } else { in_mc._visible=true; out_mc._visible=false; trace("in"); } } checkPosition(Void); var mouseListener:Object = new Object(); mouseListener.onMouseMove = function():Void { mouse_dx = Math.abs(mouse_dx-_xmouse); mouse_dy = Math.abs(mouse_dy-_ymouse); mouseSpeed = mouse_dx > mouse_dy ? mouse_dx : mouse_dy; mouseSpeed +=1; checkPosition(Void); mouse_dx=_xmouse; mouse_dy=_ymouse; } Mouse.addListener(mouseListener);
For some reason it’s not working for me
it does… nothing.
that is not a function, it’s a property… it’s not working!
I used this script in a project some years ago. There might be something else in your code that is not allowing it to work. There also might be a small error here; however, it should be easy to debug.
Simply reading it right now, I can see one character that has been clobbered by the WordPress code plugin. You should be able to figure it out.