2012-10-22 1 views
0

이 배경 음악은 메뉴에서 재생됩니다. 플레이어가 "시작"버튼 (startBtn)을 선택할 때마다 원활하게 페이드 아웃되도록하고 싶습니다. 어떻게 그걸합니까? 다음은 내 코드입니다 :액션 스크립트 3 Flash CS6 - 오디오 페이드 아웃

import flash.events.Event; 
import flash.events.MouseEvent; 
import flash.system.fscommand; 
import flash.media.Sound; 
import flash.media.SoundChannel; 
import flash.net.URLRequest; 
import flash.events.Event; 
import flash.media.SoundTransform; 
import flash.events.MouseEvent; 

//Declare MUSIC Variables 
var musicSelection:Sound; 
var musicChannel:SoundChannel; 
var musicTrack:String = "music/dearly_beloved.mp3"; 
var musicVolume:Number=0.2; 
/*var isMuted = false;*/ 

loadMusic(); 
function loadMusic():void 
{ 
    //first stop old sound playing 
    SoundMixer.stopAll(); 
    musicSelection = new Sound(); 
    musicChannel = new SoundChannel(); 
    //create and load the required soun 
    musicSelection.load(new URLRequest(musicTrack)); 
    //when loaded - play it 
    musicSelection.addEventListener(Event.COMPLETE, musicLoaded); 
} 

function musicLoaded(evt:Event):void 
{ 
    //finished with this listener 
    musicSelection.removeEventListener(Event.COMPLETE, musicLoaded); 
    //play music 
    playMusic(); 
} 

function playMusic():void 
{ 
    //play the random or selected music 
    musicChannel = musicSelection.play(); 
    //setting the volume control property to the music channel 
    musicChannel.soundTransform = new SoundTransform(musicVolume, 0); 
    //but add this one to make repeats 
    musicChannel.addEventListener(Event.SOUND_COMPLETE, playAgain); 
} 

function playAgain(evt:Event):void 
{ 
    // remove this listener and repeat 
    musicChannel.removeEventListener(Event.SOUND_COMPLETE, playAgain); 
    playMusic(); 
} 

이 두 번째 프레임의 코드입니다

import flash.events.Event; 
import flash.media.SoundTransform; 

stop(); 

optionBtn.addEventListener(MouseEvent.CLICK, goToOption) 
function goToOption(event:MouseEvent):void 
{ 
    nextFrame(); 
} 

startBtn.addEventListener(MouseEvent.MOUSE_DOWN, stopMusic); 
function stopMusic(event:MouseEvent):void 
{ 
    musicChannel.soundTransform = new SoundTransform(musicVolume, 0); 
    while (musicVolume > 0) 
    { 
     musicVolume--; 
    } 
} 

quitBtn.addEventListener(MouseEvent.MOUSE_DOWN, closeGame); 
function closeGame(event:MouseEvent):void 
{ 
    fscommand("quit"); 
} 

답변

0

사용하는 동안 ... 단지 바로 음악을 감소 - 한 프레임. 당신이해야 할 일은 ENTER_FRAME 이벤트를 추가하고 그 안에 음악을 줄이는 것입니다. 이런 식으로 뭔가 :

addEventListener(Event.ENTER_FRAME, onLoop); 

var _oldTime:Number = 0; 
private function onLoop(e:Event):void 
{ 
    var resultTime:Number = getTimer() - oldTime; 
    if(resultTime > 200) 
    { 
     musicVolume -= 0.1; 
     oldTime += resultTime; 
     if(musicVolume <= 0) 
     { 
     removeEventListener(Event.ENTER_FRAME,onLoop); 
     } 
    } 
} 

당신이 원하는 속도에 따라이 볼륨을 감소시키는 다른 값을 시도하거나 감소 (결과는 시간> 200 -> 200 밀리 초) 당신은 밖으로 트위닝 할 TweenMax를 사용할 수