我正在使用swf对象嵌入swf。我正在尝试使用外部接口从JS调用flash函数,但遇到了麻烦。我搜索了所有的文档,读了很多东西,我确信我做得对。任何人都可以指出问题可能在哪里吗?
var flashvars = {};
var params = {wmode:"opaque", allowscriptaccess:"always" };
var attributes = {id:"MySwf", name:"MySwf"};
swfobject.embedSWF("MySwf.swf", "flashContent", "600", "400", "9.0.0", "swfs/expressInstall.swf", flashvars, params, attributes,function(e){
if(e.success){
_flashRef = e.ref;
testExternalInterface();
}else{
alert("We are sorry, flash is required to view this content.");
}
});
function testExternalInterface(){
var swf = document.getElementById("MySwf");
swf.sendMeTheGoods("TEST TEST");
};
上面是我的flash中的嵌入代码和js函数
if (ExternalInterface.available)
{
trace("adding external interface");
ExternalInterface.addCallback("sendMeTheGoods", sendMeTheGoods);
}
public function sendMeTheGoods(text:String):void
{
trace("setting vars")
trace(text);
txtYouSent.text = text;
}
我收到错误Uncaught TypeError:Object#没有方法'sendMeTheGoods'
我已经尝试过引用document.getElementById(“MySwf”);和document.getElementById(“flashContent”);我两种方式都得到错误。有什么建议吗?
答案 0 :(得分:0)
外部接口API不是立即可用的,它需要一秒钟才能准备就绪。您的回调可能在Flash Player初始化EI API之前发生。尝试在回调中添加延迟,延迟调用“测试”功能。
答案 1 :(得分:-1)
var swf = navigator.appName.indexOf(“Microsoft”)!= -1? window [“MySwf”]:document [“MySwf”];