Rewriting AS code for some effects

I want to use buttons which look like they have a spring attached.

I’m quite happy with the effect, the problem is, each buttons is generating its on onClipEvent to check its distance from the mouse. I’d like to know if there would be a simpler way of doing this (so I wouldn’t have to duplicate the function to each button). If the mouse could figure out when it’s in a button area and start the effect on that button only…

It would alleviate some cpu usage I guess =)

Here’s the code I use for each button right now:

onClipEvent (load) {
	_root.springpower = 0.6;
	_root.springdistance = 40;
	this.origix = this._x;
	this.origiy = this._y
	this.buttonVar = "Portfolio";
}
onClipEvent (enterFrame) {
	this.distance = Math.sqrt((_parent._xmouse-origix)*(_parent._xmouse-origix)+(_parent._ymouse-origiy)*(_parent._ymouse-origiy));
	if (distance<=_root.springdistance) {
		this._x = this._x+(_parent._xmouse-this._x)/_root.springpower;
		this._y = this._y+(_parent._ymouse-this._y)/_root.springpower;
	} else {
		this._x = this.origix;
		this._y = this.origiy;
	}
}

cheers

mlk