I checked out this article only to find that the trick he’s used apparently only works in Flash 5. I’ve added one line to the script so it works in Flash 6+. This initialises two variables, xp and yp, as new numbers.
The script is now:
onClipEvent (load) {
// inertia relates to the quantity of energy that
// the spring will carry
// inertia = 1 would mean that the spring doesn't
// loose any energy, and that it will oscillate
// forever
inertia = 0.9;
// k relates to the spring, and how "hard" it will be.
// The higher k the faster the mass will come back.
k = 0.1;
xp = yp = new Number();
}
onClipEvent (enterFrame) {
// We calculate the distance to the mouse
x = -_x+_root._xmouse;
y = -_y+_root._ymouse;
//We calculate the amount by which the mass will to move
xp = (xp*inertia)+(x*k);
yp = (yp*inertia)+(y*k);
//We move it
_x += xp;
_y += yp;
}
FLA attached.
Perhaps an amendment could be made to the article?