# Fade sound in and out using AS3?

**URL:** <https://forum.kirupa.com/t/fade-sound-in-and-out-using-as3/268819>\
**Category:** Uncategorized\
**Created:** [August 19, 2008, 10:39am UTC](https://forum.kirupa.com/t/fade-sound-in-and-out-using-as3/268819 "2008-08-19T10:39:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![yokiki](https://avatars.discourse-cdn.com/v4/letter/y/258eb7/32.png) [@yokiki](https://forum.kirupa.com/u/yokiki)\
**Post date:** [August 19, 2008, 10:39am UTC](https://forum.kirupa.com/t/fade-sound-in-and-out-using-as3/268819/1 "2008-08-19T10:39:26Z")

</div>

Hi,

I have made an animation of a garden and i want the garden sound to play until the user clicks a certain tomato which starts a sequence to the next scene - then i want to sound to fade out to mute.

sooo… i want to fade in a sound when the animation starts then fade out when the user click a button.

i attach a .fla of my rough set up… the isnt a sound on there as my garden sound made the .fla to big to upload.

i also found this code on here but don’t really know how to apply it or if it is the right thing:

[COLOR=DarkGreen]import fl.transitions.Tween;  
import fl.transitions.easing.\*;  
import fl.transitions.TweenEvent;  
var myTransform=SoundMixer.soundTransform;  
var myTween:Tween;  
myButton.addEventListener(MouseEvent.CLICK, toggleMute);  
function toggleMute(evt) {  
if (SoundMixer.soundTransform.volume==1) {  
myTween=new Tween(myTransform, “volume”, None.easeNone, 1, 0, 3, true);  
myTween.addEventListener(TweenEvent.MOTION\_CHANGE, changeVolume);  
} else {  
myTween.stop();  
myTransform.volume=1;  
SoundMixer.soundTransform=myTransform;  
}  
}  
function changeVolume(evt) {  
SoundMixer.soundTransform=myTransform;  
}[/COLOR]

thank you very much for any help!

Kira
