さて、私は自分が作成している Web サイト用の単純な 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