2011-11-06 59 views
0

我正在使用AS3庫StandingWave並試圖讓「完成」事件觸發音頻播放器。我有下面的代碼,事件似乎從未開火。我沒有得到跟蹤而不是按鈕重新啓用。AS3駐波庫完成事件不會觸發

var player:AudioPlayer = new AudioPlayer(); 
play_btn.addEventListener(MouseEvent.CLICK,playSinewave); 

function playSinewave(e:Event):void{ 
var sinewave:IAudioSource = new SineSource(new AudioDescriptor(),5,440,0.2); 
play_btn.enabled = false; 
player.addEventListener(Event.COMPLETE,doComplete); 
player.play(sinewave); 
} 

function doComplete(e:Event):void{ 
trace("COMPLETE") 
play_btn.enabled = true; 
} 

回答

0

問題是,player.play(sinewave);不會觸發Event.COMPLETE。我認爲它可能觸發SampleDataEvent.SAMPLE_DATA。 Event.COMPLETE在加載聲音源時觸發。下面的代碼應該有所幫助:

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

//Load the song. 
var song:Sound = new Sound(); 
var songChannel:SoundChannel = new SoundChannel(); 

song.addEventListener(Event.COMPLETE, hdSongLoaded); 
song.load(new URLRequest("assets/songs/VMBach.mp3")); 

//Buttons 
buttons.onBTN.addEventListener(MouseEvent.CLICK, hdSoundOn); 
buttons.offBTN.addEventListener(MouseEvent.CLICK, hdSoundOff); 
buttons.skipBTN.addEventListener(MouseEvent.CLICK, hdSkip); 

//Handlers. 
function hdSongLoaded(e:Event) { 
    //e.currentTarget.play(); 
    songChannel = song.play(); 
} 

function hdSoundOn(e:MouseEvent) { 
    songChannel = song.play(); 
} 

function hdSoundOff(e:MouseEvent) { 
    songChannel.stop(); 
} 

function hdSkip(e:MouseEvent) { 
    //removeChild(onBTN); 
    //removeChild(offBTN); 
    removeChild(buttons); 
    songChannel.stop(); 
    gotoAndStop(2); 
} 

stop();