The forums have permanently moved to
forum.kirupa.com. This forum will be kept around in read-only mode for
archival purposes. To learn how to continue using your existing account on the new forums,
check out
this thread.

Fade out audio clip when clicking a button?

I have intro audio music playing on a project I am working on. The audio is in the timeline (but doesn't necessarily have to be), and when I click a button to move away from it, it just keeps playing. I can use SoundMixer.stopAll(); to make is stop as you click the button, but this makes a rather harsh abrupt stop to the music that is undesirable. I would like to have it fade the audio track out once the button is clicked.

I have heard of TweenMax before, and tried to get it to work but couldn't. Do you know what I need to do to get it installed and functioning? I have downloaded it, and read the "Usage", but it didn't seem very complete. Is there anywhere else to go for more info on how to use this?

Okay. I got TweenLite working. It seems to be loading the sound, but now I want the sound to fade out after a button click. Anyway to do that?
I couldn't find that functionality on their documentation.

Does not the link posted by snickelfritz work? It seems to be well documented. Take a look at http://www.greensock.com/tweenlite/, at the Plugin Explorer section. There is a usage example. I haven't tried it but it seems that the volume plugin is included in the free package you have downloaded. Hope it helps.

Does not the link posted by snickelfritz work? It seems to be well documented. Take a look at http://www.greensock.com/tweenlite/, at the Plugin Explorer section. There is a usage example. I haven't tried it but it seems that the volume plugin is included in the free package you have downloaded. Hope it helps.

ANd it loads and plays the audio perfectly, but I need to add a function to a button to fade the volume down and turn it off. It seems like the last two functions do that, but I don't understand them enough to know how to make a button do those things, and I can't find anything anywhere that tells me how to do that, even though they have an example of it, but I can't find the code for the example.

I have never used the TweenLite's onUpdate function, but if I had to perform an audio fadeout from a button I would do something like this:

Code:

import com.greensock.*;
import flash.events.MouseEvent;
var someSound = new Sound(new URLRequest("audio_new/flatwound_-_The_Long_Goodbye.mp3"));
var someChannel = new SoundChannel();
var someTransform = new SoundTransform(1);//volume is set to the max
someChannel = someSound.play(0, 99, someTransform);//The sound will start from 0 millisecond, will loop 99999 times and will use the someTransform SoundTransform
//the next lines are for fading out the volume
// fadeOut_btn is a button you've created on the stage
fadeOut_btn.addEventListener(MouseEvent.CLICK, soundFadeOut);
function soundFadeOut(evt:MouseEvent):void
{
TweenLite.to(someSound, 1, {volume:0, onComplete:stopSound});
}
function stopSound():void
{
someChannel.stop();
}

Let me know if it works.

No, that doesn't work. If I put the even listener on the first frame, it does't do anything. And If I put the button script on the frame where I want it to trigger, then it throws a "unknown function" error.

Here's an example that uses a movieclip as button that starts or stops the sound.
the movieclip has 2 keyframes: "play", which shows a standard play icon, and "pause" which shows a standard pause icon.

The movieclip is on the stage and named "btn".
clicking btn toggles play and pause, and tweens the volume up or down accordingly.
The code is fairly self-explanatory.

BTW, use TweenMax for this; the volume plugin is activated by default.

The thing I am trying to say here, is I need the sound click to load and start playing on Frame 1. But way down when you hit frame 45, that is where I want the fade to start. Trigger the fade to begin on frame 45, not when the thing loads immediately. If I move the script off the frame that loads the audio, then it errors out.

What I need:

1) The audio track to load when you load the site.
2) The audio track to fade out when you hit specified frame. (or it could be triggered by a button on specified frame)

I wouldn't think this would be that hard. Anyone have any idea how to do this?