FORUMS: list search recent posts

Fading sound based on frame location

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Tony Westerfield
Fading sound based on frame location
on Feb 26, 2010 at 7:23:30 pm

Any ideas on how to trigger a fade out once playhead reaches a frame? I know I need actionscript 3.0, but personally need a tutorial. Any clues?

Thanks.

Tony W


Return to posts index

demetri tashie
Re: Fading sound based on frame location
on Feb 26, 2010 at 8:08:35 pm

there are probably several different ways to do this. here's one way, using a Timer

-you create a Timer which will run a function a specific amount of times, every specified time interval. for this , maybe have it run every second, for 5 times

your function just sets the volume to decrease by .2 - so running it 5 times fades it down to zero over 5 seconds

you will need to put an ENTER_FRAME listener to the stage, which will know when it enters every frame.
your function says: if the frame number( or frame label) is such and such, then cary out the code, which triggers the timer, which start our fade.

not too bad, right?

assuming you have your Sound and SoundChannel (depends if yo uuse an internal or external sound)set up correctly, you also need to establish a SoundTransform, which in this case will transform the volume.

here's some code to take care of all this from the point of declaring a Soundtransform object onwards.
you will see that the timer triggers every second (1000 = 1 second), 5 times,
and that it triggers on entering frame 20

var snTr:SoundTransform = new SoundTransform();

stage.addEventListener(Event.ENTER_FRAME, stageListener);
function stageListener(event:Event):void{
if(currentFrame==20){myTimer.start() }
}

var myTimer:Timer = new Timer(1000, 5);

myTimer.addEventListener(TimerEvent.TIMER, fadesOut);

function fadesOut(event:TimerEvent):void{
snTr.volume -= .2;
snCh.soundTransform=snTr;
}


there's plenty of info out there to explain anything within the code.
hope that helps.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]