Follow Mouse with Flash 5

This tutorial will walk you through how to make a movie clip follow your mouse cursor in all directions or on the x or y axis.

For this example I have chosen to add 3 frames with multiple layers to my move, each with a stop action and specific action on the follow mouse cursor clip to demonstrate different variations to this technique. Each example is just a slightly different ActionScript that is attached to each clip instance. These snippets of code are reusable and can easily be modified to suit you particular needs.

1) First we will open a new movie and create a movie clip symbol with either a static graphic or an animation of your choice. I have chosen to use a simple static figure.

2) The first frame of the movie above, shows an example of a movie clip that follows the users cursor anywhere it goes while the cursor is over the Flash movie. This is achieved with the following AcrionScript;


onClipEvent (mouseMove) {
_x = _root._xmouse;
_y = _root._ymouse;
updateAfterEvent();
}

3)The second example shows the movie clip follow the users cursor at a fixed position along the x axis;


onClipEvent (mouseMove) {
_x = _root._xmouse;
updateAfterEvent();
}

4) The third example shows the Movie Clip following the users cursor at a fixed position on the y axis;


onClipEvent (mouseMove) {
_y = _root._ymouse;
updateAfterEvent();
}

 

Download the source file for this example

:: organic:pixel ::

[ back ]