Custom Mouse Pointer

Following The Mouse

Let's create a function that gets the pointer MovieClip to follow the mouse across the stage. Create a new function with the the Name onEnterFrame. It is important that you follow the capital letters EXACTLY as you see them. onEnterFrame is a built-in function that repeats the Actions inside the braces. If your movie is set to 24FPS, the script runs (hypnotically) 24 times per second.

You will know if you have it right because Flash turns the onEnterFrame script blue:

Now set the x position of the pointer MovieClip on the stage using ActionScript. X position is one of many MovieClip properties you can dynamically set using ActionScript. Flash refers to the x position as _x ("Underscore" x). To reference a MovieClip property, start with the Instance Name of the MovieClip, follow with a "dot", and add the property. To set the x position of our pointer MovieClip we use: pointer._x

We want pointer._x to be equal to the x position of the mouse, which we can determine using the built-in property: _xmouse. Therefore, our script is pointer._x = _xmouse; We can get that script as part of the onEnterFrame function using set variable:

  1. Select the opening line of the onEnterFrame function so the new script goes inside the braces
  2. Click Statements > Variables > and Double-Click set variable
  3. Variable name is pointer._x
  4. Value is _xmouse
  5. Select the Expression box for Value ONLY

Repeat the process for the _y position (vertical position) of the pointer MovieClip. Your script should look like this when you finish:

Test the movie. The pointer MovieClip should follow the mouse perfectly.

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player