Custom Cursors
//Custom Cursor - Basics
//Hide the default mouse cursor
Mouse.hide();
//Listen for and and respond to mouse movement
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
function onMove(e:MouseEvent) {
//reset your movieclip to the mouseX and mouseY positions
yourclip_mc.x = mouseX;
yourclip_mc.y = mouseY;
//upate after the mouse event to reduce screen-refresh lag
e.updateAfterEvent();
}
/////////////////////////////
//Custom Cursor - More Advanced with Rotate to Mouse
//Hide the default mouse cursor
Mouse.hide();
//Listen for and and respond to mouse movement
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
function onMove(e:MouseEvent) {
//rotate your clip to the mouse using some trigonometry
//dx and dy represent distance between your clip and the mouse location
var dx = mouseX - fly_mc.x;
var dy = mouseY - fly_mc.y;
//use the distance to calcuate the angle in radians
var radians:Number = Math.atan2(dy, dx);
//convert radians to degrees to get approprate rotation and apply it to clip
var targetrotation:Number = radians * 180/Math.PI;
fly_mc.rotation = targetrotation;
//reset your movieclip to the mouseX and mouseY positions
fly_mc.x = mouseX;
fly_mc.y = mouseY;
fly_mc.play();
//upate after the mouse event to reduce screen-refresh lag
e.updateAfterEvent();
}
//Add listeners to play the cursor movieclip on mouse events
stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
function onDown (e:MouseEvent) {
fly_mc.gotoAndStop(15);
}
stage.addEventListener(MouseEvent.MOUSE_UP, onUp);
function onUp (e:MouseEvent) {
fly_mc.gotoAndStop(1);
}