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?

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;
function dragSlider(event:MouseEvent):void {
function stopSlider(event:MouseEvent):void {
function setVolume(event:Event):void {
ratio_volume = track_mc.slider_mc.x/widthPos;
soundVol.volume = ratio_volume;
revChan.soundTransform = soundVol;
revChan.soundTransform = soundVol;

Open in new window

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:


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

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.