Question : 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.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
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 Select All

Answer : Flash CS3 Volume slider - preserving volume

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.

Random Solutions  
 
programming4us programming4us