Flash & Swish  Home Flash & Swish Flash Tutorials Mouse Follower
rss

Mouse Follower

Author: Webzo Studio More by this author


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:

image 1

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: www.webzo.org

Rate this Material: Bad 1 2 3 4 5 Excellent
print this page tell a friend subscribe to newsletter subscribe to rss

Add comments to "Mouse Follower"