Thursday, October 8, 2009

Show Hand Cursor on Flash AS3 Sprite , MovieClip

To show Hand Cursor on a Flash MovieClip or Sprite that listens for MouseOver events, add the following code:

mClip.buttonMode=true;

where mClip is the Sprite or MovieClip that listens for MouseOver events.
If mClip contains a TextField within it, add this line :

mClip.mouseChildren=false;

To try out the example code below, copy and paste the code in your Flash IDE.

var mc:Sprite=new Sprite();
mc.graphics.beginFill(0xffff00,1);
mc.graphics.drawRect(0,0,100,30);
mc.graphics.endFill();
var t:TextField=new TextField();
t.text="Text inside Sprite";
mc.addChild(t);
mc.addEventListener(MouseEvent.MOUSE_OVER,Over);
mc.addEventListener(MouseEvent.MOUSE_OUT,Out);
addChild(mc);
mc.x=100;
mc.y=100;
mc.buttonMode=true;
// mc.mouseChildren=false; // Uncomment this line to display HandCursor
function Over(e:MouseEvent):void
{
//handle event
}
function Out(e:MouseEvent):void
{
//handle event
}

No comments:

Post a Comment