all groups > flash actionscript > november 2007 >
You're in the

flash actionscript

group:

Fade sound using AS3


Re: Fade sound using AS3 damonlee
11/3/2007 12:00:00 AM
flash actionscript: Ok, here is my latest code:

var soundFadeInTimer:Timer = new Timer(100,30);
soundFadeInTimer.addEventListener("timer", soundFadeIn);

soundFadeInTimer.start()

var fadeInIncr = 0.1;

function soundFadeIn(e:TimerEvent){
fadeInIncr += 1/30;
trace(fadeInIncr)
}

var snd:Sound = new Sound(new URLRequest("myLoop.mp3"));
var trans:SoundTransform = new SoundTransform(fadeInIncr, 0); // 1=vol, 0=pan
var channel:SoundChannel = snd.play(0, 1, trans);

When viewing the trace output, the "fadeInIncr" varible is being increased
like it is supposed to.
However, the volume is not increasing.

Any Ideas?
Fade sound using AS3 damonlee
11/3/2007 2:17:15 AM
I'm trying to write a function that will Fade In a given mp3 called via the
following method:

var sAmbience:Sound = new Sound();
sAmbience.load(new URLRequest("ambience.mp3"));
var sAmbienceVol:SoundTransform = new SoundTransform(0.7, 0);

I also want a function that will Fade Out the sound...I knew how to do this in
AS2

Any help would be greatly appreciated.

Thx -D



Re: Fade sound using AS3 kglad
11/3/2007 2:23:31 AM
you sound (sAmbience.play() ) returns a soundchannel instance which has a
soundTransfrom property. that soundTransform property has a volume property
that will set the volume for your sound (sAmbience).

you can use any loop (ENTER_FRAME or timer) to fade that volume property.
Re: Fade sound using AS3 damonlee
11/3/2007 2:32:01 AM
kglad,
Thank you for your response.

I trigger the sound to play like this:

sAmbience.play(0,1,sAmbienceVol)

and that of course starts playing the mp3 no problem, so your saying
decrement/increment the "sAmbineceVol" ?

Could you give me an example of the loop? I realize your not here to "write
my code for me", but this seems to have me stumped.

Re: Fade sound using AS3 kglad
11/3/2007 6:47:51 AM
read the help files. i listed all the steps involved. here they are in code:



var sc:SoundChannel = sAmbience.play(0,1);
AddThis Social Bookmark Button