Problems with spring

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.

// 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;
``````

}

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

``````