I have made a simple yet quite useful custom cursor class in this case is in AS2. All that is needed is a movieclip that will take use of it. This also doesn’t make the mouse flicker with constant Mouse.hide() calls, it stays hidden only when on focus with the swf. If you know how to extend a movieclip this would look very very simple and easy.
Custom Cursor Class - sample swf
The class extends the movieclip class therefore inherits all of a movieclip’s properties, methods and events. With a cursor all we would practically need is the onMouseMove event. See this custom cursor on the work from my game, Puttbase.
class MCCursor extends MovieClip { static var cur:MCCursor; var frame:Object; var onMouseMove2:Function; function MCCursor(){ Mouse.hide(); gotoAndStop(1); if ( cur ) { cur.removeMovieClip(); } // singleton class cur = this; // swap to a very high but still safe depth swapDepths( 1048031 ); } function onMouseMove(){ _x += _xmouse; _y += _ymouse; onMouseMove2(); } }
Basically this is all we would need. The class is singleton (restricted to only one instance) so the instanced movieclip is stored on the static variable cur. First create a movieclip, name it whatever you want, set a linkage identifier and, most importantly, have “MCCursor” as its class (see figure below). The class may vary if you’re using a separate folder to contain all your classes but I’ll leave explaining that on another time.

Figure screenshot
To instantiate, either leave the cursor movieclip on stage during design time, where the class is instanced when the movieclip appears on stage, or attach them during run time like this:
var cur = _root.attachMovie( 'mcCursor', 'cur', _root.getNextHighestDepth() );
Now to add some other functions to make some jobs and our life easier:
This hides the mouse pionter again when the swf regains focus:
var onMouseDown2:Function; function onMouseDown(){ Mouse.hide(); /** * force update position, not totally * necessary but might be useful somehow * */ this.onMouseMove(); onMouseDown2(); }
If you want to have your own onMouseDown event function you can use onMouseDown2 instead, so to not overwrite this method, do something like:
MCCursor.cur.onMouseDown2 = function(){ //do what you want }
To handle a better gotoAndStop function:
var frame:Object; /** * f parameter can be a number or a string (frame label), * it will be stored on frame variable regardless * if it is a valid frame from the movieclip or not * */ function gotoAndStop( f:Object ) { super.gotoAndStop( f ); frame = f; } /** * f is a numeric value or string of the made frame label * */ static function gotoFrame( f:Object ) { if ( !cur ) return; cur.gotoAndStop( f ); } /** * set getFrameNumber parameter to true to force returning the * actual numberic value of the current frame of the movieclip * */ static function getFrame( getFrameNumber:Boolean ):Object { if ( !cur ) return null; if ( getFrameNumber ) return cur._currentframe; else return cur.frame; }
For convenience, use the this static function to set the frame of the cursor and can be accessed anywhere (MCCursor class must be imported on the class to recognize it):
MCCursor.gotoFrame( f );
…have these on the class then it’s good to be used.
Grab the actual Class AS file here which also quite commented.
This is a v0.1 so it is a simple but is really expandable class. I’ll update this with new methods and features when something comes up and is necessary. An AS3 version will also be made soon.
Other Keywords:
- Change Actionscript 2 mouse cursor
- Flash mouse pointer
- Custom mouse pointer
- Personal mouse cursor
- Replace default cursor with custom mouse pointer





( 4.00 / 5 from 4 votes )
•
4 Jan 09 at 7:20 pm
Hi! Can you also provide the .fla of the sample swf here in your tutorial? I like how the cursor changes when it hovers the button. I would like to use your Action Class in my website. Thank you.
4 Jan 09 at 9:36 pm
Never mind. I got it. Thank you again.
3 May 10 at 9:58 am
Senor Santos,
Podria usted por favor, facilitarme el FLA file que corresponde con su classe …?
De antemano agradeciendole, desde Holanda,
Carlos
22 May 10 at 6:08 am
I just have a “simple” AS2 question… Is there anyway I can reposition the cursor or mouse position when you hit a button. I need to move the mouse out of the button in order for the button to be hidden.
thanks in advance.
22 May 10 at 11:53 am
I don’t think there is a way (yet). Flash is not allowed to natively reposition mouse positions.
I’m not 100% certain, but why would there be a problem on hidding the button after being clicked?
18 Mar 11 at 5:49 pm
Hi,
is it possible to change the cursor only when it goes over a certain button?
I hope you can help me!
Regards, Elis