0
好的,所以我正在爲我正在製作的網站使用我簡單的actionscript-3聲音播放器......並且雖然這樣做,但發生了SOUND_COMPLETE事件由於某種原因不會起火。所以,如果有人似乎注意到我的代碼中的問題,請回復!Actionscript 3:Event.SOUND_COMPLETE不會觸發
package {
import flash.events.*;
import flash.media.*;
import flash.external.*;
import flash.net.*;
import flash.utils.*;
public class player{
private var soundChannel:SoundChannel;
private var sound:Sound;
private var lastPosition:Number = 0;
public function player():void{
ExternalInterface.addCallback("load", this.load);
ExternalInterface.addCallback("play", this.play);
ExternalInterface.addCallback("stop", this.stop);
ExternalInterface.addCallback("reset", this.reset);
}
/*
javascript from inside actionscript:
ExternalInterface.call("console.log","ipsum");
*/
private function load(url:String):void{
var audio:URLRequest = new URLRequest(url);
try {
this.soundChannel.stop();
} catch(e:Error) {
};
this.sound = new Sound();
this.sound.load(audio);
this.lastPosition = 0;
}
private function play():void{
this.soundChannel = this.sound.play(this.lastPosition);
this.soundChannel.addEventListener(Event.SOUND_COMPLETE,finished);
ExternalInterface.call("console.log","started playing");
}
private function finished():void{
this.lastPosition=0;
this.soundChannel=this.sound.play()
ExternalInterface.call("console.log","finished playing");
}
private function reset():void{
this.lastPosition = 0;
this.soundChannel.stop();
}
private function stop():void{
try {
this.lastPosition = this.soundChannel.position;
this.soundChannel.stop();
} catch(e:Error) {
};
}
}
}//package
http://www.untoldentertainment.com/blog/2009/10/14/as3 -pitfalls-sound_complete-event-is-not-firing/ – adaam 2013-04-29 20:13:30
這在這種情況下不適用於我,因爲每次我使用播放函數時,都會再次添加EventListener。 感謝您的回覆! – 2013-04-29 20:15:27
我認爲你應該在加載時調用你的本地停止函數,並且我認爲你在finished()函數中得到了一個運行時錯誤,因爲它不能接受它將被傳遞的事件。運行時錯誤阻止了代碼的恢復運行。我只能假設你沒有看到它,因爲你禁用了調試,或者沒有在調試播放器中運行它。 – 2013-04-29 20:51:34