Copy link to clipboard
Copied
Hi
I have a infinite music loop and I am trying to have btn_start trigger a fade out on the music along with its original gotoAndPlay.
I have two scenes, "opening" and "animation". btn_start and the following code are in the "opening" scene.
the fade out will play along with the first couple seconds of "animation" since the gotoAndPlay connects to frame 1 of "animation"
Can this be done? Please show me some lights of how to proceed this.
stop();
import flash.net.URLRequest;
import flash.media.Sound;
var url:URLRequest = new URLRequest("subtle.mp3");
var snd:Sound = new Sound(url);
snd.play(0, 17);
btn_start.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndPlay(1, "animation");
}
thanks!!
you can use:
...
stop();
import flash.net.URLRequest;
import flash.media.Sound;var fadeRate:Number = .01; // number between 0 and 1. the closer to 1, the faster the fade
var url:URLRequest = new URLRequest("subtle.mp3");
var snd:Sound = new Sound(url);
var sc:SoundChannel=snd.play(0, 17);
btn_start.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
this.addEventListener(Event.ENTER_FRAME,fadesoundF);
gotoAndPlay(1, "animation");
}function fadesound
Copy link to clipboard
Copied
you can use:
stop();
import flash.net.URLRequest;
import flash.media.Sound;var fadeRate:Number = .01; // number between 0 and 1. the closer to 1, the faster the fade
var url:URLRequest = new URLRequest("subtle.mp3");
var snd:Sound = new Sound(url);
var sc:SoundChannel=snd.play(0, 17);
btn_start.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
this.addEventListener(Event.ENTER_FRAME,fadesoundF);
gotoAndPlay(1, "animation");
}function fadesoundF(e:Event):void{
var st:SoundTransform=sc.soundTransform;
st.volume-=fadeRate;
if(st.volume<=0){
this.removeEventListener(Event.ENTER_FRAME,fadesoundF);
}
sc.soundTransform=st;
}
Copy link to clipboard
Copied
works PERFECT!
millions thanks kglad!
Copy link to clipboard
Copied
you're welcome.