Newest Articles

8 Ball Pool
Photo Reel
Image Color Tinting using Actionscript
3d Rotating Image Cube
Image Slider with Easing
Catapult Game


Popular Articles

True Fullscreen Flash Mode
8 Ball Pool
FLV Player
Image Slider
Mp3 Player with XML Playlist
Album Slide


Random Articles

Growing Tree using Recursion
Focus in on an Image
Infinitely Zooming Image
XHTML Image Mapper
LED Text Scroller
Motion along a Path


Links

Foundation-Flash
Tutorial4Me
MickM
TutorialQuest
Tutorialsphere.com - Free Online Tutorials
Newgrounds
TWiT
Link to SwfSpot
Swf Spot



rss feed

Custom Mouse Cursor

Custom Mouse Cursor
AddThis Social Bookmark Button
Description: Remove the default mouse cursor and replace it with your own
Author: John Bezanis
Added: March 1st 2007
Version: Flash 8
Total Views: 8724
Views in the Past 7 Days: 129


This simple tutorial demonstrates how to replace the default cursor with a custom one.
First, draw the cursor you'd like to use. Select the graphic using the Selection Tool. Right-Click and select Convert to symbol. Set the name to cursor, the type to Movie Clip, and click Export for ActionScript. Make sure the Identifier is set to cursor. Click OK. Double-click the newly created symbol open and to edit the cursor's position. Move the position so it suits your needs, and double-click the stage outside of the graphic area. This will bring you back to the main level. Now that the cursor graphic is finished, click it and hit delete on the keyboard. It is ok to delete the graphic because it has been added to the library, so we can re-add it using actionscript. Click somewhere on th stage and open up the Actions Frame and insert the following code:
  1. Mouse.hide();
  2. this.attachMovie("cursor", "cursor", this.getNextHighestDepth());
  3. cursor.onMouseMove=function(){
  4.   cursor._x=_xmouse;
  5.   cursor._y=_ymouse;
  6.   cursor.swapDepths(this.getNextHighestDepth());
  7.   updateAfterEvent();
  8. }
This code hides the mouse, replaces it with the newly created graphic, and on each frame moves the new cursor to the current mouse position.

The source file is available below for download.
Download Source File
Questions and Suggestions
how would you keep the cursor on top if there is other action script also calling for the next highest depth, (see "Instantiating an Object").
March 22nd 2007 23:03PM   -   Mr. P
I've added in the line cursor.swapDepths(this.getNextHighestDepth()); to keep the cursor at the highest depth.
March 23rd 2007 07:03AM   -   John
How would you change the color of your custom mouse while your using it in your movie? I'm making a "coloring book" and want my custom mouse to change to the color that is being clicked.
October 10th 2007 00:10AM   -   Ronda
How do you prevent it from braking once you right click?
November 4th 2007 01:11AM   -   Tommy
Why not place an instance of the cursor symbol, give it an instance name of "cursor_mc" and simplify your code to just: cursor.startDrag("true"); Mouse.hide(); rt
November 12th 2007 01:11AM   -   rt
rt, yeah that works as well.
November 12th 2007 08:11AM   -   John
I put it the code it won't work
December 21st 2007 20:12PM   -   Flashy Games
Now it works thanks for putting up the code!
December 21st 2007 21:12PM   -   Flashy Games
how make visual effects and advance Mouse cursor by ActionScript2.0
February 4th 2008 03:02AM   -   om Prakash
cool codes. john's code is for the use of cursor's meaning. By using cursor.startDrag("true"); it's another meaning already. it's all depends on wad function you want then use the appropriate methods ;-)
March 31st 2008 03:03AM   -   xy
i made a button for a cursor but when i click on things it only activates the cursor button, and not things in the movie. how do i get the cursor to do something when mouse is clicked along with whatever is clicked on??
April 12th 2008 03:04AM   -   chris
Add a Question or Suggestion
name:
website (optional):
captcha type the characters into the box
message (5000 characters or less):