Saturday, July 17, 2010

Mouse.cursor property in Actionscript 3

Sometimes it is needed to change the default mouse cursor to an already built-in cursor (hand, finger pointer, etc). Here's an example:



You can change the cursor like this:
Mouse.cursor="hand";
or
Mouse.cursor=MouseCursor.HAND;
So the code to the above example would be:
import flash.events.MouseEvent;

autoBtn.addEventListener(MouseEvent.ROLL_OVER, over);
ibeamBtn.addEventListener(MouseEvent.ROLL_OVER, over);
buttonBtn.addEventListener(MouseEvent.ROLL_OVER, over);
handBtn.addEventListener(MouseEvent.ROLL_OVER, over);
arrowBtn.addEventListener(MouseEvent.ROLL_OVER, over);

autoBtn.addEventListener(MouseEvent.ROLL_OUT, out);
ibeamBtn.addEventListener(MouseEvent.ROLL_OUT, out);
buttonBtn.addEventListener(MouseEvent.ROLL_OUT, out);
handBtn.addEventListener(MouseEvent.ROLL_OUT, out);
arrowBtn.addEventListener(MouseEvent.ROLL_OUT, out);

function over(event:MouseEvent){
 switch (event.currentTarget){
  case autoBtn:
  Mouse.cursor="auto";
  break;
  case ibeamBtn:
  Mouse.cursor="ibeam";
  break;
  case buttonBtn:
  Mouse.cursor="button";
  break;
  case handBtn:
  Mouse.cursor="hand";
  break;
  case arrowBtn:
  Mouse.cursor="arrow";
  break;
  default:
  Mouse.cursor="auto";
  }
 }
 
function out(event:MouseEvent){
 Mouse.cursor="auto";
 }

There are only 5 possible options for this property, and this was introduced in Flash Player 10, Flash CS4.

3 comments:

Anonymous said...

Hi is there a way to make it work on flash cs3 ?

Thanks

Anonymous said...

Спасибо!

Georgit said...

Thanks very much,you saved my day!

Post a Comment