# Sound volume = cursor distance?

**URL:** <https://forum.kirupa.com/t/sound-volume-cursor-distance/196985>\
**Category:** flash\
**Created:** [August 12, 2006, 12:18pm UTC](https://forum.kirupa.com/t/sound-volume-cursor-distance/196985 "2006-08-12T12:18:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kindoki](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@kindoki](https://forum.kirupa.com/u/kindoki)\
**Post date:** [August 12, 2006, 12:18pm UTC](https://forum.kirupa.com/t/sound-volume-cursor-distance/196985/1 "2006-08-12T12:18:16Z")

</div>

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:

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