Custom Mouse Pointer

The init Function

Now let's create a function that runs when the movie first loads. It's very common to call this function init (short for initialize) although this is a made up name. So, rename Layer 1 Actions, select the first frame, and bring up the ActionScript dialogue box:

  1. Click Statements > User-Defined Functions and Double-Click functions
  2. Name this new function init

Now we have to make the init function actually do something. Let's bring the "pointer" onto our empty stage by adding the attachMovie method to the function arguments:

  1. First, make certain you have the START of the function init() { script selected. We want our action to go between the braces
  2. Click ActionScript 2.0 Classes > Movie > MovieClip > Methods and Double-Click attachMovie

Now set the arguments for the attachMovie function:

  1. Type the Object name _root
  2. Type the Linkage Name pointer and Deselect the Expression box
  3. Type the New Name pointer and Deselect the Expression box
  4. Set a Depth of 1

Let's analyze what's happening in the above script.

First: the Object is _root which is something you will be seeing and hearing allot. For now you can consider _root to be Flash's built-in Instance Name for the stage (notice how Flash turns _root blue in the ActionScript window? That means it's part of a built-in function). Though you can attachMovie to a different MovieClip (using an instance name) in this case we just want it on the stage.

Second: Linkage Name refers to the Identifier you created in the Linkage Properties box. You deselect the Expression box because pointer isn't a variable that needs to be evaluated - it's a literal name.

Third: New Name is where you dynamically set the Instance Name of the MovieClip. I decided to call it pointer. Notice the quotes - pointer is a string literal, and not a variable. We COULD use variables to dynamically set the name. Maybe another time.

Fourth: The Depth! Every MovieClip placed on the stage with ActionScript has to have it's own depth. It's rather like the stacking order of layers in the timeline. Since this is the only clip we are using right now, we are starting with a Depth of 1. If we were to place another object on the stage with a depth of 1, our "pointer" would completely disappear. Remember that!