sound 제어
from_ greenass hansune
As 3.0
/*
1. 나무등장할때(새소리결합__embed
2. 들어가는 소리1__embed
3. 분자 들어가는 소리__embed
4. 마지막 빠져나갈때
5. 새소리
6. 성공
7. 실패
8. 엔터
9.인트로 팝업
10. 인트로 배경
11. 키보드 잘못 클릭
12. 클릭
13.클릭2
14. 클릭 3
15. 키보드 클릭
*/
var vol:Number = 1.0;
var volStep:Number = 0.05;
var tgVol:Number;
var bgch:SoundChannel;
var bgsound:Sound = new Sound ();
var sndtimer:Timer = new Timer(100,20);
sndtimer.addEventListener(TimerEvent.TIMER,dwVol);
/////일회성 플레이
function snd(n:int) {
var url:String = "data/"+n+".mp3";
trace(url);
var s:Sound = new Sound();
s.addEventListener(Event.COMPLETE, onSoundLoaded);
var req:URLRequest = new URLRequest(url);
s.load(req);
}
function onSoundLoaded(event:Event):void
{
var localSound:Sound = event.target as Sound;
localSound.play();
}
//////////////////
//////////////////사운드 제어를 위한..
//////////////////
function sndIoErrorHandler(event:Event):void {
trace("ioErrorHandler: " + event);
}
function sndcompleteHandler(event:Event):void {
trace("Snd completeHandler: " + event);
bgch.stop();
bgch = bgsound.play();
bgch.addEventListener(Event.SOUND_COMPLETE, sndcompleteHandler);//위에서 사운드채널을 다시 했기때문에..
setVolume(vol);
}
BGsnd();
function BGsnd() {
bgsound = new Sound();
bgsound.addEventListener(IOErrorEvent.IO_ERROR, sndIoErrorHandler);
var url:String = "data/bg.mp3";
var request:URLRequest = new URLRequest(url);
bgsound.load(request);
bgch = bgsound.play();
bgch.addEventListener(Event.SOUND_COMPLETE, sndcompleteHandler);
var transform:SoundTransform = new SoundTransform(vol, 0.0);
bgch.soundTransform = transform;
}
function BGsndOff():void {
//var transform:SoundTransform = new SoundTransform(0.0, 0.0);
//bgch.soundTransform = transform;
bgsound.close();
}
function BGsndDown():void {
vol = 1;
volStep = -0.05;
tgVol = 0;
sndtimer.start();
}
function BGsndUp():void {
vol = 0;
volStep = 0.05;
tgVol = 1;
sndtimer.start();
}
function dwVol(e:TimerEvent):void {
vol = vol + volStep;
if (Math.abs(vol - tgVol) < 0.05) {
vol = tgVol;
sndtimer.stop();
//bgch.stop();
}
setVolume(vol);
}
function setVolume(volume:Number):void {
var transform:SoundTransform = new SoundTransform(volume, 0.0);
bgch.soundTransform = transform;
}

