好的,所以我正在为我正在制作的网站开发我的简单 actionscript-3 声音播放器......在这样做的同时,我发现 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