0
這裏是我的動作中類變量(編譯mxmlc的,嵌入到HTML和功能調用JS):錯誤訪問的ExternalInterface的回調
package {
import flash.display.Sprite;
import flash.external.ExternalInterface;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
public class LyrePlayer extends Sprite {
private var out:SoundChannel;
private var player:Sound;
public function LyrePlayer() {
out = new SoundChannel();
player = new Sound();
ExternalInterface.addCallback("play", play);
ExternalInterface.addCallback("stop", stop);
}
private function play(url:String):void {
var request:URLRequest = new URLRequest(url);
player.load(request);
if(out.position != 0) out.stop();
out = player.play();
}
private function stop():void {
out.stop();
}
}
}
這一切工作,排序的。我可以播放一個文件,並撥打stop()
任意多次。但是如果我第二次撥打play()
,則會報錯:
> flashObject.play("/static/test.mp3")
[the song plays]
> flashObject.stop()
[the song stops]
> flashObject.play("/static/test.mp3")
Error
arguments: undefined
message: "Error calling method on NPObject."
> flashObject.stop()
[no error]
任何想法?
我不知道你問什麼,但如果你的意思是,如果你從out.stop()行取出//你的播放功能,你會得到一個錯誤,不會在第一次調用播放時觸發錯誤,因爲out變量沒有設置爲SoundChannel的實例嗎? –
我修正了這個問題,並澄清了我的問題。謝謝。 – colinmarc
嘗試更改ExternalInterface回調名稱,而不是播放lyrePlay。 –