# Inertia in Flash MX (re: article)

**URL:** <https://forum.kirupa.com/t/inertia-in-flash-mx-re-article/160286>\
**Category:** open source\
**Created:** [August 24, 2005, 7:44pm UTC](https://forum.kirupa.com/t/inertia-in-flash-mx-re-article/160286 "2005-08-24T19:44:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aneurin\_Mark\_II](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/aneurin_mark_ii/32/1564_2.png) [@Aneurin\_Mark\_II](https://forum.kirupa.com/u/Aneurin_Mark_II)\
**Post date:** [August 24, 2005, 7:44pm UTC](https://forum.kirupa.com/t/inertia-in-flash-mx-re-article/160286/1 "2005-08-24T19:44:46Z")

</div>

I checked out [this article](http://www.kirupa.com/developer/actionscript/spring.htm) 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:

```auto
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? 🙂
