Task: Follow the Mouse

I l @ ve RuBoard

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:

     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 .

I l @ ve RuBoard


Sams Teach Yourself Flash MX ActionScript in 24 Hours
Sams Teach Yourself Flash MX ActionScript in 24 Hours
ISBN: 0672323850
EAN: 2147483647
Year: 2002
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net