# Problems with spring

**URL:** <https://forum.kirupa.com/t/problems-with-spring/59968>\
**Category:** Uncategorized\
**Created:** [August 5, 2004, 6:08am UTC](https://forum.kirupa.com/t/problems-with-spring/59968 "2004-08-05T06:08:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thinker2501](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@Thinker2501](https://forum.kirupa.com/u/Thinker2501)\
**Post date:** [August 5, 2004, 6:08am UTC](https://forum.kirupa.com/t/problems-with-spring/59968/1 "2004-08-05T06:08:09Z")

</div>

I’m trying to make a box change dimensions with a spring motion. In terms of doing the resizing it works normally, but when I try to apply a modified version of the spring tutoral code it doesn’t work. I’ll copy and past the code and attach my file, any help would be appriciated.

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.7 ;

```
// k relates to the spring, and how "hard" it will be.
// The higher k the faster the mass will come back.
k = 0.2 ;
boxW = 200;
boxH = 200;

```

}  
onClipEvent (enterFrame) {  
// Centers movie in \_root  
centerX = 275;  
centerY = 200;  
movieW = Math.floor(\_width/2);  
movieH = Math.floor(\_height/2);  
xCenterLoc = (centerX-movieW);  
\_x = xCenterLoc;  
yCenterLoc = (centerY-movieH);  
\_y = yCenterLoc;

```
// Spring Calculations
cornerHeight = (topLeftCorner._height + bottomLeftCorner._height);
cornerWidth = (topLeftCorner._width + topRightCorner._width);
// We calculate the distance to the mouse
deltaW = -_width + (boxW + cornerWidth);
deltaH = -_height + (boxH + cornerHeight);
//We calculate the amount by which the mass will to move
wp = wp * inertia + deltaW*k ;
hp = hp * inertia + deltaH*k ;
//We move it
topBar._width += wp ;
bottomBar._width += wp;
leftBar._height += hp ;
rightBar._height += hp;

// Move right side graphics to new X position
xLoc = topLeftCorner._width + topBar._width;
topRightCorner._x = xLoc;
rightBar._x = xLoc;
bottomRightCorner._x = xLoc;
// Move bottom graphics to new Y position
yLoc = topLeftCorner._height + leftBar._height;
bottomLeftCorner._y = yLoc;
bottomBar._y = yLoc;
bottomRightCorner._y = yLoc;

```

}

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 5, 2004, 7:18am UTC](https://forum.kirupa.com/t/problems-with-spring/59968/2 "2004-08-05T07:18:40Z")

</div>

Make sure to define wp and hp, otherwise you’ll get NaN and the effect won’t work. So just add wp = 0; and hp = 0; to the onClipEvent(load) and you’ll be fine 🙂

```auto

onClipEvent (load) {
	wp = 0;
	hp = 0;
	k = 0.2 ;
	boxW = 200;
	boxH = 200;
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 5, 2004, 4:39pm UTC](https://forum.kirupa.com/t/problems-with-spring/59968/3 "2004-08-05T16:39:40Z")

</div>

thanks, that was it.
