Avg. Rating 4.7

Problem

You want to create a custom cursor to match the look and feel of your game, design, experience, etc.

Solution

Create your own cursor, in this tutorial, an image with a transparent background was used.

Detailed explanation

 (This tutorial uses a PNG butterfly (which is credited to jadersworld.com))
Get yourself a transpaprent PNG cursor.

 
Import it and create a movieclip. Let's call it myCursor, in properties Export for Actionscript. This should also show up as "myCursor."
 
//Always stop everything, even if you think nothing's running.
stop();
var cursor:MovieClip;
//Hide the mouse
Mouse.hide();
// Call my first function
init(); 
function init()
{
 //hide your mouse again
 Mouse.hide();
 //call the movieClip with your mouse art
 cursor = new myCursor();
 cursor.visible = false;
 // mouse enabled, a user can interact with it by using a mouse
 cursor.mouseEnabled = false;
 //children of the object are mouse enabled
 cursor.mouseChildren = false;
 //add to the stage
 addChild(cursor);
 //add mouse move by calling the function onStage
 stage.addEventListener(MouseEvent.MOUSE_MOVE, onStage);
//add EventListener for when the Mouse Leaves the stage
 stage.addEventListener(Event.MOUSE_LEAVE, offStage);
}

 
function onStage(e:MouseEvent):void
{
 //controls x position 
cursor.x = e.stageX;
//controls y position
cursor.y = e.stageY;
//show cursor when mouse is on stage
cursor.visible = true;
}


function offStage(e:Event):void
{
//hides cusor when mouse isn't over flash movie
 cursor.visible = false;
}
  

 There's also the option to create other Mouse Functions if you'd like.

cursor.zip
[Download the cursor fla]

+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes