Sound fading issues....help anyone?

I have a presentation, that plays a sound loop, over and over throughout the movie…(guess that’s why they call it a loop )

Here’s my problem:

On the first frame of my Main movie timeline…I have this code:

[AS]
firstSound=new Sound();
firstSound.attachSound(“musicloop01”);
myLoopVolume=50;
firstSound.setVolume(myLoopVolume);
_root.firstSound.start(0,999);

[/AS]

I also have a vertical volume control MC on the main time line with the following code:

[AS]

onClipEvent(load) {
left=_root.base._x -6;
top=_root.vslider._y + 50;
right=_root.base._x -6;
bottom=_root.vslider._y - 50;
volCalc=_root.vslider._y - 50
}
onClipEvent(enterFrame) {
vslidery=_root.vslider._y;
_root.firstSound.setVolume(100-(vslidery-volCalc));
}
//
onClipEvent(mouseDown) {
startDrag(this, false, left , top , right, bottom);
}
//
onClipEvent(mouseUp) {
this.stopDrag();
}

[/AS]

So far so good, everything works…

However,

I wanted to fade this loop out at the end of the last movie…so…I entered this code…attached to a MC somewhere down the timeline:

[AS]

// set up variables on load
onClipEvent(load){
so = _root.firstSound; // object, not string
rate = 1;
startFadeOut = true;

}

// fade out loop
onClipEvent(enterFrame){
if(startFadeOut){
if(so.getVolume() > 0) {
so.setVolume(so.getVolume() - rate);
} else {
so.setVolume(0) // prevent negative values
startFadeOut = false; //stop loop
}
}
}

[/AS]

Well, WITHOUT, the volume control MC, the fade out works…perfect…depending where it is on the time line…when it reaches it , it fades.

However, WITH the volume control, fadeout doesn’t do anything…

I really need to get this to work, I’ve read many tutorials here and on Flashkit, but none of them addresses this issue with the fade out AND volume control together.

It doesn’t help that I’m new to the whole sound object thing.

Any help would be greatly appreaciated!!!:slight_smile:

Well, looks to me like your fadeout script is fine. I believe what’s happening is that when you have both the fadeout script and the volume control on at the same time, the fadeout reduces volume by “rate” every frame, but the volume slider sets the volume at the slider’s value every frame. So the net result is no change in volume.

Easy fix is to check for the startFadeout variable in the slider script. If startFadeout is true, then have the volume slider disabled.

Hope that helps.

-Al

hey, thanks for the response…

question though…

what you said makes sense…but I’m not to good at this…all of the current code I have was snatched from tutorials…

First…would you mind showing me the code to accomplish this…

and

Second…if it disables the slider…can it be re-enabled?..in other words…if I wanted to fade out a song…then fade in another one…but at the same time…giving the user control of the volume?

Thanks a bunch!

Here’s a quick and dirty solution.

First of all, you’ll need to reference the fade out movie clip. So let’s label it myFader and I’m assuming it’s on the root timeline.

Replace your volume slider AS with the following:

[AS]
// No changes made to your code here.
onClipEvent(load) {
left=_root.base._x -6;
top=_root.vslider._y + 50;
right=_root.base._x -6;
bottom=_root.vslider._y - 50;
volCalc=_root.vslider._y - 50
}

// Changes have been made to your code here.
onClipEvent(enterFrame) {
// If the fadeOut process has started, then simply move the vslider to the current volume level:
if(_root.myFader.startFadeOut) {
_root.vslider._y = _root.firstSound.getVolume + volCalc;
// Otherwise the fadeOut process has not begun so set the volume to the vslider’s level:
} else {
vslidery=_root.vslider._y;
_root.firstSound.setVolume(100-(vslidery-volCalc));
}
}

// Changes made here too. Not sure if this checking is necessary, as it may use a minute amount of processing power, but I know it will work with it in.
onClipEvent(mouseDown) {
if(_root.myFader.startFadeOut){
startDrag(this, false, left , top , right, bottom);
}
}
onClipEvent(mouseUp) {
this.stopDrag();
}
[/AS]

That should do it. So the volume slider is disabled when the fadout script is running, but you can see the slider move down as the volume decreases. Hope you understand what the code is actually doing. If you have questions, just ask.

-Al