Sounds fade in/out with ActionScript 3

CrociDB picture CrociDB · Oct 6, 2010 · Viewed 13.5k times · Source

I am trying to make a fade in/out in a music in a Flash (CS5) project. I imported the sound to library, set a classname for "Export for ActionScript", and I was trying to fade with TweenLite/TweenMax, like this:

var sound = new MySound();
sT = new SoundTransform(0.1);
sound.play(0,99999, c_sndEnvironment);
TweenLite.to(sound, 1, {volume: 1.0});

But it just doesn't work. I tried to import the volume plugin on TweenLite, and still nothing. I got no error at all though.

Am I doing anything wrong?

Plus, is there any good (complete) AS3 library for music?

Thank you. :)

Answer

PatrickS picture PatrickS · Oct 6, 2010

I use TweenMax for this , it's pretty straightforward

var someSound:Sound = new Sound(new URLRequest(“MySound.mp3″));
var someChannel:SoundChannel = someSound.play(0, 99999);
TweenMax.to(someChannel, 1, {volume:0, onComplete:stopSound});

http://www.greensock.com/tweenmax/