Search Our Web Design Blog...

Tuesday, November 15, 2011

Custom Cursor...

A little more confusing to make it work:

The code (based on a movie clip named MyCursorClass with a Linkage set to MyCursorClass:




import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;

var myCursor:Sprite;

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

function init()
{
    Mouse.hide();

    // this creates an instance of the library MovieClip with the
    // name, "MyCursorClass".  this contains your mouse cursor art
    //
    myCursor = new MyCursorClass();
    myCursor.mouseEnabled = false;
    myCursor.visible = false;
   
    // you'll want to make sure the child is added above everything
    // else, possibly in its own container
    //
    addChild(myCursor);
   
    // respond to mouse move events
    stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
    stage.addEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler);
}

function mouseMoveHandler(evt:MouseEvent):void
{
    // whenever the mouse moves, place the cursor in the same spot
    myCursor.visible = true;
    myCursor.x = evt.stageX;
    myCursor.y = evt.stageY;
}

function mouseLeaveHandler(evt:Event):void
{
    myCursor.visible = false;
}

init();

No comments:

Post a Comment