Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

music loop fade out by button between scenes

New Here ,
Jul 04, 2011 Jul 04, 2011


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!!

TOPICS
ActionScript
618
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 04, 2011 Jul 04, 2011

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

...
Translate
Community Expert ,
Jul 04, 2011 Jul 04, 2011

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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 04, 2011 Jul 04, 2011

works PERFECT!

millions thanks kglad!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 04, 2011 Jul 04, 2011
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines