Sound volume = cursor distance?

Hi guys,

I have this mc in my movie, and I want the volume of a certain sound to increase/fade up as the cursor gets closer to the mc, and also want it to decrease/fade down as the cursor gets away from the mc.

I’ve got this code:

onClipEvent (load) {
	s_jam = new Sound(this);
	s_jam.attachSound("jam");
	s_jam.start(0, 999);
	s_jam.setVolume(0);
	startVol = 100;
}
onClipEvent (enterFrame) {
	xSide = _root._xmouse-this._x;
	ySide = _root._ymouse-this._y;
	hypo = Math.sqrt((xSide*xSide)+(ySide*ySide));
	if (hypo<100) {
		if (jamStopped == true) {
			s_jam.start(0, 999);
			jamStopped = false;
		}
		deltaV = startVol-(startVol*(hypo*.01));
	} else {
		deltaV = 0;
		s_jam.stop();
		jamStopped = true;
	}
	s_jam.setVolume(deltaV);
}

But it seems pretty archaic, since I think it was done for flash 5, and also I want to be able to customize the distance at which the sound starts to fade.

Does anybody know someway of doing it, or how to fix this code?