I see stars
A number of users have asked how to make a mouse follower. If you are not familiar with mouse followers, just swipe your cursor across the demonstration movie clip below and you’ll get the idea. We have created a component to make it easier for you to include a mouse follower in your movie. All you need to do is add your artwork to the container movie clip and then add an effect.
This component will be included in a future installer of SWiSH Max2 and SWiSH miniMax2, but for now the component (MouseFollower.swi) and the example file (MouseFollower_example.swi) can be obtained from mousefollower.zip.
To use the component, copy ‘MouseFollower.swi’ into your components / Effects / 2D folder. This can normally be found at
C:\Program Files\SWiSH Max2\components\Effects\2D
If you are running Max2 (or miniMax) when you copy the component, you may need to refresh the component tree by right clicking on the tree in the Components panel then selecting ‘Reload’.
To use the component, simply drag it into your movie.
The component has two parameters, Maximum Shadows and Orient Object. The Parameters panel can be opened (if it is not already visible) using main menu | Window | Parameters.
Use a smaller number for Maximum Shadows if you want to see a smaller trail. If Orient Object is set to ‘true’, then the container movie clip is oriented according to the direction of the mouse movement. To make best use of this you should setup the container movie clip to initially point right.
To change the object that is displayed, expand the component in the Outline panel, then place a new shape (or shapes) within the container movie clip.
The shapes should be centered within the movie clip. To do this, set x, y to 0 (zero) in the Transform or Reshape panels.
Once you have added your shapes, you can remove the original arrow, then you should apply some effects to your shapes. I find the Move effect convenient for this. Using the same effect you can set the _alpha to transparent (essential if you want the following objects to fade out), change the size and also define a different final color. The effect settings I used for the arrow demonstration are shown below:
I hope you have fun with this component. Below I explain how the component and example movie work. This discussion is probably only of interest to advanced users.
Enjoy!
General Movie Layout Explanation
The movie is constructed using multiple scenes. This provides a convenient way to show multiple effects. The movie was initially created with a single effect, then that scene was copied to provide the additional scenes. For the multiple scenes to work correctly, the Stop playing at end check box in the Properties panel must be checked in all scenes.
A standard component button Buttons | Pushbutton | Button is used to control progress to the next (or first) scene. The Event Goto options are altered for each button to either goto the next scene, or in the case of the last button, to go to the first scene. This and the button label and tooltip can be altered using the Parameters panel.
The border shape is used to provide an outline so that the boundaries of the movie can be seen. In addition, the shape has the following script added to fade the instruction text in and out as the mouse passes over and away from the movie.
onSelfEvent (rollOver, dragOver) {
_parent.instructions.gotoAndPlay("FadeOut");
}
onSelfEvent (rollOut, dragOut, releaseOutside) {
_parent.instructions.gotoAndPlay("FadeIn");
}
The instructions movie clips is used to contain the text. It has the following script which defines the areas of the timeline to be played when a FadeIn or FadeOut effect is needed.
onFrame(1) {
setLabel("FadeIn");
}
onFrame (61) {
stop();
}
onFrame (100) {
setLabel("FadeOut");
}
onFrame (131) {
stop();
}
Due to an optical illusion that makes the eye think the fade in occurs faster than the fade out, I have extended the fade in effect to cover 60 frames, while the fade out effect only covers 30 frames.
Mouse Follower Scripting Explanation
The mousefollower component contains two sub movie clips, mousedrag and container.
During the mousefollower’s onSelfEvent(load) event it duplicates the container movie clip according to the value set by parameters.MaxShadows. Doing this duplication during the load is more efficient than dynamically creating and destroying movie clips as they are needed. This script will create multiple container clips named “container_0″, “container_1″, …” container_N” where N is the highest number which will be equal to parameters.MaxShadows-1.
onSelfEvent (load) {
var i;
for (i=0;i<parameters.MaxShadows;i++)
{
// duplicate the container movieclip so that there is
// container_0.. container_N
// where N is parameters.MaxShadows-1.
container.duplicateMovieClip("container_" add i, i+1);
}
}
The container movie clip (mousefollow.container) has the following script for it’s on load event.
onSelfEvent (load) {
_visible = false;
}
This script is essential to ensure that the movie clip is not visible when it is duplicated.
The bulk of the processing is done by the sub movie clip ‘mousedrag’ which has the following load event function:
onSelfEvent (load) {
startDrag(_target, true); // make this MC follow the mouse.
var posX = _x; // note the initial position so we can detect movement
var posY = _y;
var nextmc = 0; // use this as the first shadow movie clip ie container_0
var mc0Depth = _parent.parameters.MaxShadows; // initial depth for mc0
var dx;
var dy;
var ang = 0;
}
This script associates the otherwise emtpy movie clip with the mouse via startDrag() and initialises the other variables. It is worth noting that mc0Depth defines the base level that container movie clips will be placed once they are activated.
The onSelfEvent (enterFrame) function of mousedrag does the bulk of the work.
onSelfEvent (enterFrame) {
if ((_x != posX) || (_y != posY)) {
// have moved.
var i, j;
if (_parent.parameters.OrientToDirection) {
// orient the container based on the current movement
// assumes container object is initially pointing right
dx = _x - posX;
dy = _y - posY;
ang = Math.atan2deg(dy,dx);
_parent["container_" add nextmc]._rotation = ang;
}
// update the saved position so we can see if we move in the future
posX = _x;
posY = _y;
// setup the new container object to display current cursor position
_parent["container_" add nextmc]._x = _x;
_parent["container_" add nextmc]._y = _y;
_parent["container_" add nextmc]._visible = true;
_parent["container_" add nextmc].gotoAndPlay(1);
_parent["container_" add nextmc].swapDepths(nextmc+mc0Depth); // make this the highest level so it is on top
nextmc++; // move onto the next container object for next time
if (nextmc >= _parent.parameters.MaxShadows) {
// have cycled through all available container movie clips.
// move the movie clips back to their base level.
nextmc = 0; // cycle back to the first movie clip
for (i = 0; i<_parent.parameters.MaxShadows; i++) {
// move existing movie clips below mc0Depth
_parent["container_" add i].swapDepths(i+1);
}
}
}
}
On each frame it checks to see if the mouse has moved from the last time it checked. If the mouse has not moved, then nothing happens.
It then checks to see if the OrientToDirection parameter has been set. If it has, then it works out the new angle based on trigonometry and the previous mouse position.
The current position is then saved so that only new mouse movements will activate the display of another movie clip.
The next available movie clip (nextmc) is then setup as follows:
x and y position is set according to current mouse position.
The movie clip is made _visible.
The movie clip is made to start playing from frame 1 so any user effect is replayed.
The depth is changed so that this movie clip is now the highest. Note that mc0Depth is above all of the other clips when they are created, so nextmc+mc0Depth will be the highest level.
nextmc is then incremented so that the next movie clip is used next time the mouse is moved.
After incrementing nextmc, a check is made to see if it is past the last movie clip. If it is, then it is set to the first movie clip (0) and all of the existing movie clips are moved to their original level by the for loop.
Tags: follower, mouse, mouse follower


(10 votes, average: 4.50 out of 5)

wow!that was great!!!