Flash CS3 Volume slider - preserving volume

I am using this code to adjust volume using a fader.

It is working fine, but when I restart the audio, and do not recall this function, even though the fader stays in place at the correct position, the volume goes back to default until I touch the fader, then it pops back down to the fader position volume.

I have tried making all of the variables private, is there anyway of me preserving the volume level that the fader is at when the audio restarts?

thanks.
private function VolumeSlider(){
soundVol = new SoundTransform();
 
trackBounds = track_mc.getBounds(track_mc);
xPos = trackBounds.x;
yPos = 0;//trackBounds.y;
widthPos = trackBounds.width-track_mc.slider_mc.width;
heightPos = 0;
bounds = new Rectangle(xPos,yPos,widthPos,heightPos);
track_mc.slider_mc.x = widthPos;
track_mc.mouseEnabled = false;
track_mc.slider_mc.buttonMode = true;
 
track_mc.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN,dragSlider);
stage.addEventListener(MouseEvent.MOUSE_UP,stopSlider);
 
function dragSlider(event:MouseEvent):void {
event.target.startDrag(false,bounds);
addEventListener(Event.ENTER_FRAME,setVolume);
}
 
function stopSlider(event:MouseEvent):void {
track_mc.slider_mc.stopDrag();
removeEventListener(Event.ENTER_FRAME,setVolume);
}
function setVolume(event:Event):void {
trace(track_mc.slider_mc.x/widthPos);
ratio_volume = track_mc.slider_mc.x/widthPos;
soundVol.volume = ratio_volume;
revChan.soundTransform = soundVol;
revChan.soundTransform = soundVol;
 
}

Open in new window

lexshineAsked:
Who is Participating?
 
lexshineConnect With a Mentor Author Commented:
I figured this out.

What I did was remove this line:

track_mc.slider_mc.x = widthPos;

which was setting the default fader position, then used the following code:

track_mc.slider_mc.x/100;

to track the fader position at all times. Then just used soundTransform at thos coordinates.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.