Flash Script
none none none
none How to Create a Custom Cursor

Also posted on Knol: Create Image Cursor Actionscript3

Summary
How to create a custom cursor in Flash and ActionScript 3.

The steps are:
Create a sprite object, and add a bitmap image to it.
Add MouseMove event listener to the new cursor object.
Hide the system cursor (by calling Mouse.hide();)
Update the x and y coordinates of the new cursor on the MouseMove events that we receive.


Note
There are two points that are usually forgotten when one quickly whips out a custom cursor the first time.

1)
One needs to pass the mouse events to the objects BELOW our custom cursor, our custom cursor should no longer receive these events since it replaced the system cursor. We do this by setting the function mouseEnabled to false

newCursor.mouseEnabled = false;

2)
Every time the cursor moves we redraw the image (unless you are running flash at high refresh rate). This will prevent the lagging response of the cursor as you move it around the screen. This is down by calling the function updateAfterEvent.

e.updateAfterEvent();


Flash



Code
(Cut and paste the code below into your 'actions' window, Window -> Actions. To execute, Control -> Test Movie)

none
none none none







History Licensing & Pricing Privacy Policy Contact Us
Frequently Asked Questions