Home > Articles > Graphics & Web Design > Dreamweaver & Flash

  • Print
  • + Share This
This chapter is from the book

Task: Follow the Mouse

Now that you know how to get the mouse location, and you know how to set the location of a movie clip, you can combine these two pieces to make a movie where a movie clip follows the cursor around the screen.

  1. Create a new Flash movie.

  2. Make a simple movie clip. Something like a small circle will do.

  3. Attach the following script the to movie clip:

  4. onClipEvent (enterFrame) {
      this._x = _root._xmouse;
      this._y = _root._ymouse;
    }

That's all there is to it. Check out the sample movie 07followthemouse.fla. When you test the movie, the movie clip immediately snaps to the location of the mouse, provided that the mouse is over the test window.

In Hour 13, "Rollovers," we'll look at how to use a similar technique to create custom cursors.

  • + Share This
  • 🔖 Save To Your Account