ActionScript3:Custom Mouse Pointers

From virtualMV2015wiki
Jump to: navigation, search
 Home  Flash10 (CS4) <


Use a custom graphic as a mouse pointer using ActionScript 3

Icon Objective.png


By the end of this exercise you should be able to:

  • Create a customised mouse pointer

Create the Graphic

Using graphic software such as Adobe Photoshop, Corel Draw or PaintShop Pro, create a graphic to be used in place of the standard mouse pointer. Photoshop has a great range of shapes, including one resembling a barrel crosshair sight. Create with a transparent background, save as a png and import to the stage of your Actionscript 3 movie.

Convert to a movieClip, tick the Export For Actionscript checkbox and give it a class name of Cursor. Give the movieClip an instance name of crosshair and then delete from the stage. The movieClip will still reside in the Library and will be called via ActionScript.

Inserting the ActionScript

Open the Actions panel on frame One of your actions layer and insert the following code:

var crosshair:MovieClip;
function shootMe ():void
    crosshair = new Cursor();
    addChild (crosshair);
    crosshair.enabled = false;
    stage.addEventListener (MouseEvent.MOUSE_MOVE, dragCursor);
function dragCursor (event:MouseEvent):void
    crosshair.x = this.mouseX;
    crosshair.y = this.mouseY;

To change the mouse pointer back to normal as it passes over a button for example, use an eventListener on the button for a MOUSE_OVER Event and use the Mouse.Show() function. Use MOUSE_OUT as the mouse leaves the button.

Icon References.png References


Day, S. (2010). ActionScript3:Custom Mouse Pointers. Retrieved December 17, 2017, from