我使用 swfobject 加载了我的 swf。我从 AS3 中调用 FB.ui 来显示付费窗口。至此一切正常。 支付完成后,FB.ui 调用本应回调到 AS3 的回调。我获得了对 swf 对象的引用,但实际方法调用失败,对象不支持属性或方法。
我一直在阅读关于此的每篇文章,但找不到任何帮助。在我看来,getElementById 没有返回正确的对象。
这只发生在 IE 中。 Chrome 和 FireFox 工作正常。
var attributes = {};
attributes.id = "game";
attributes.name = "game";
attributes.align = "middle";
swfobject.embedSWF(
"game.swf", "flashContent",
"800", "600",
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);
// JavaScript enabled so display the flashContent div in case it is not replaced with a swf object.
swfobject.createCSS("#flashContent", "display:block;text-align:left;");
.....
FB.ui(obj, function(data) {
if(!data) {
alert("There was an error processing your payment. Please try again!");
return;
}
// alert('called back order');
// IMPORTANT: You should pass the data object back to your server to validate
// the contents, before fulfilling the order.
var gameVar = document.getElementById("game");
//alert(gameVar);
//console.log(Object.prototype.toString.call(gameVar));
//alert(gameVar.purchaseCallback);
gameVar.purchaseCallback(data);
//console.log("Payment verification complete");
});
//handle errors here
//alert('some error');
return false;
}
如果我将以下内容添加到页面,那么这个奇怪的地方是单击链接有效。 功能测试() { var game = document.getElementById("游戏"); 警报(游戏.purchaseCallback); } 测试
最佳答案
原来问题出在 visibility 上。由于 FB.ui 在显示 FB.ui 对话框时更改对象的可见性,然后在处理对话框时将其更改回来,因此 Flash 应用程序失去了它的 ExternalInteface。
为了更正这个问题,我添加了:
<style>
#game {
visibility: visible !important;
}
</style>
我还要补充一点。在 IE 8 中,这可能无法正常工作。我对 swf 的参数进行了以下更改,它现在似乎适用于所有内容。
params.wmode = "opaque";
关于javascript - swfobject、FB.ui 回调、AS3 ExternalInterface 和 IE 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20807455/