Friday, 12 February 2010

Custom cursor in AS3 part 2

I previously created the custom cursor in AS3 tutorial where the cursor object was initially placed on the stage. In this tutorial I will be dynamically adding the cursor object onto the stage from the library. For more information on dynamically adding objects on the stage, checkout the AttachMovie in Actionscript 3 tutorial.

Custom cursor in AS3 part 2

Step 1

Open a new Flash AS3 file. Then create your custom cursor on the stage. I will be creating the exact same cursor from the previous tutorial. You can create whatever you wish.

Step 2

Convert your object into a movie clip (F8). Give an appropriate name and select the centre registration point. Then check the ‘Export for Actionscript’ tab and click ok. If you receive an Actionscript class warning message, click ok.

**Depending on the style of your custom cursor you may need to change the registration point.

Step 3

Select your cursor movie clip on the stage and delete it. This will leave you with nothing on the stage.

Step 4

On the timeline insert a new layer called Actions then open up the Actions panel and enter the following code.

//This creates a new instance of the cursor movie clip and adds it onto
//the stage using the addChild method.
var mycursor_mc:cursor = new cursor();

//Hides the default cursor on the stage so it will not be shown.

//Adds an event listener onto the stage with the enter frame event which
//repeatedly executes the moveCursor function.
stage.addEventListener(Event.ENTER_FRAME, moveCursor);

//This function set the x & y positions of the custom cursor to the x & y positions
//of the default cursor.
function moveCursor(event:Event) {

Step 5

Test your movie clip Ctrl + Enter.

You should now be able to dynamically add a custom cursor onto the stage.


Ali 19 March 2012 at 08:40  

Hi there, your guide is really useful so thanks! i had one small problem, I'm using scenes on flash, so when i use your code, it works fine on the 1st scene and there are no overlapping issues, however when i go onto the 2nd or 3rd scene etc, there are overlapping issues such as, the cursor will not appear when i highlight over a picture, can you tell me where i am going wrong?


iliketo 19 March 2012 at 13:41  


I don’t have the fla file and I can’t see your code, so it's difficult for me to tell you what wrong.

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP