Our Flash tutorials provide you with step-by-step instructions on how to create beautiful Flash animations and integrate them into your website.  Home Flash & Swish Flash Tutorials Mouse Follower

Mouse Follower


The mouse follower is a simple effect that can be used in almost anything, its one movie clip that will follow your mouse around.

The first thing to do is create the movie clip that will be following your mouse.

When you create it make sure it is positioned like this:

Mouse Follower

You can select your drawing and press "Ctrl + 2" then "Ctrl + 5" and Flash will center it automatically.

Now drag your movie clip to the stage, right click it and select Actions.

Paste this code:

onClipEvent (load)
{
      this._x = 0;
      this._y = 0;
      var speed = 20;
}
onClipEvent (enterFrame)
{
      _x += (_xmouse - _x)/speed;
      _y += (_ymouse - _y)/speed;
}

On load we set this MC position to be equal to the mouse and the speed to 20.

Those speeds work a little different, the bigger they are the slower the MC is going to move.

When Flash enters the frame we increase the MC's position by the distance between the mouse and the MC, divided by the speed.

The MC is already moving towards the mouse, but let's make the MC rotate now.

onClipEvent (load)
{
      this._x = 0;
      this._y = 0;
      var speed = 20;
      var rotSpeed = 5;
}
onClipEvent (enterFrame)
{
      _x += (_xmouse - this._x ) / speed;
      _y += (_ymouse - this._y) / speed;
      _rotation += (((_xmouse - this._x) / rotSpeed) + ((endY - this._y) / rotSpeed)) / 2;
}

his code will make the MC rotate depending on the direction and the speed he is "walking".

And just like the other speed, the bigger rotSpeed is the slower the MC will rotate.

I hope you liked this special effect and start using it on your movies.



About the Author:

Webzo Studio is a web design company located in the United States. Webzo Studio was founded in August 2005. We are a small team of designers that just love our job. The love of doing what we do is what makes us not doing our job as a job, but as an enjoyment.
read more about this author

Author's URL: Webzo Studio
Final results of our readers
New!
Passed through all the steps? Share your result!
Your result will be premoderated.
Please make sure you choose the right image.
 
 



Captcha

*Required fileds
Our Flash tutorials provide you with step-by-step instructions on how to create beautiful Flash animations and integrate them into your website. More Flash Tutorials: Featured Materials | Fresh Materials | More Flash Tutorials at FlashPerfection.com

Reader's comments
comments Bidhu March 15, 2010 says:
It's a good one
Reply
Add comments to "Mouse Follower"

Captcha