# Changing volume using mouse position

**URL:** <https://forum.kirupa.com/t/changing-volume-using-mouse-position/291406>\
**Category:** Uncategorized\
**Created:** [June 29, 2009, 12:48pm UTC](https://forum.kirupa.com/t/changing-volume-using-mouse-position/291406 "2009-06-29T12:48:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanyseanyseany](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@seanyseanyseany](https://forum.kirupa.com/u/seanyseanyseany)\
**Post date:** [June 29, 2009, 12:48pm UTC](https://forum.kirupa.com/t/changing-volume-using-mouse-position/291406/1 "2009-06-29T12:48:55Z")

</div>

Hi i am trying to create a soundscape of a photograph by making the volume of a sound increase as the cursor moves over a part of the photo which would make that sound. I am only interested in the X axis of the mouse position and know what I want my program to do but im having trouble coding it correctly.

if courser position X is less than 200 pixels, volume = 0  
if courser position X is more than 400 pixels, volume = 0  
if between 200 and 300 pixels volume = 1 - (mouseY - 200) /100  
if between 300 and 400 pixels volume = (mouseY) - 300 / 100

I have found an example code which does a similar thing but as I attempt to include if and else statements the program does not respond how I expect.

Example code,

var snd:Sound = new Sound();  
snd.load(new URLRequest(“song.mp3”));

var channel:SoundChannel = new SoundChannel();  
channel = snd.play();

var trans:SoundTransform = new SoundTransform();

this.addEventListener(Event.ENTER\_FRAME, onLoop, false, 0, true);

function onLoop(evt:Event):void {  
trans.volume = 1 - mouseY/stage.stageHeight;  
channel.soundTransform = trans;  
}

Any suggestions or a point in the right direction would be apreciated
