Skip to content

Instantly share code, notes, and snippets.

@fenixkim
Created February 20, 2013 21:23
Show Gist options
  • Save fenixkim/4999761 to your computer and use it in GitHub Desktop.
Save fenixkim/4999761 to your computer and use it in GitHub Desktop.
This snippet set up a custom cursor. You must include it into a MovieClip with is the cursor representation. Require: Flash timeline based project
import flash.events.MouseEvent;
mouseChildren = false;
mouseEnabled = false;
// Adds the events listener to the stage
stage.addEventListener(MouseEvent.MOUSE_MOVE, actualizarCursor);
stage.addEventListener(MouseEvent.MOUSE_DOWN, actualizarCursor);
stage.addEventListener(MouseEvent.MOUSE_UP, actualizarCursor);
stage.addEventListener(Event.MOUSE_LEAVE, mouseLeave);
// Handles the mouse events
function actualizarCursor (event:MouseEvent) {
Mouse.hide();
// Handles the mouse move
if (event.type == MouseEvent.MOUSE_MOVE) {
this.x = event.stageX;
this.y = event.stageY;
event.updateAfterEvent();
}
// Handles the mouse down
if (event.type == MouseEvent.MOUSE_DOWN) {
this.scaleX = 0.9;
this.scaleY = 0.9;
}
// Handles the mouse up
if (event.type == MouseEvent.MOUSE_UP) {
this.scaleX = 1.0;
this.scaleY = 1.0;
}
}
// Estas acciones se aseguran de ubicar el cursor siempre en la parte
// más alta, cuando un elemento se agrega el escenario
stage.addEventListener(Event.ADDED, enviarArriba);
function enviarArriba (event:Event) {
// Mueve el cursor a la parte más alta
stage.addChild(this);
}
function mouseLeave (event:Event) {
Mouse.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment