我正在开发一款Facebook应用程序,该应用程序在除IE以外的所有浏览器中都能正常运行,有时可以运行,有时则会失败。我正在使用ExternalInterface来处理Facebook Javascript API。似乎我的回调在IE中间歇性地设置为null。例如,当我打开邀请朋友弹出窗口时:
function inviteFriends(messageText) {
FB.ui({
method : 'apprequests',
message : messageText
}, function(response) {
console.log("onInviteFriendsComplete: " + getFlashObject().onInviteFriendsComplete);
if (response && !response.error)
getFlashObject().onInviteFriendsComplete(true);
else
getFlashObject().onInviteFriendsComplete(false);
});
}
这有时很好。控制台日志跟踪:
onInviteFriendsComplete: function () {
return eval(instance.CallFunction("<invoke name=\""+name+"\" returntype=\"javascript\">" + __flash__argumentsToXML(arguments,0) + "</invoke>"));
}
当应用程序失败时,它会跟踪:
onInviteFriendsComplete: null
当回调为空时,调试器会抛出一个对象预期错误。
此问题也会间歇性地发生在其他请求中:
function purchaseItem(packHTML) {
FB.ui({
method : 'pay',
action : 'purchaseitem',
product : packHTML
}, function(response) {
console.log("onPurchaseItemComplete: " + getFlashObject().onPurchaseItemComplete);
try {
getFlashObject().onPurchaseItemComplete(response, packHTML);
} catch(e) {
console.log("getFlashObject: " + getFlashObject());
console.log("Flash top: " + getFlashObject().style.top);
console.log("Flash visibility: " + getFlashObject().style.visibility);
}
});
}
当回调失败时,日志(来自catch语句)显示找到Flash对象而不是null。该样式在0px处显示其顶部,隐藏可见性。我正在拦截hideFlashCallback:
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : facebookAppId, // App ID from the app dashboard
channelUrl : 'channel.html', // Channel file for x-domain comms
status : true, // Check Facebook Login status
cookie : true,
xfbml : true, // Look for social plugins on the page
hideFlashCallback : onFlashHide
});
isFacebookInitialized = true;
};
function onFlashHide(params) {
console.log(getFlashObject() == params.elem);
if (params.state == 'opened') {
displayFlashScreenshot();
} else {
hideFlashScreenshot();
}
}
function displayFlashScreenshot() {
// Call the Flash ActionScript method to create the dynamic screenshot data
var flashObject = getFlashObject();
var screenshotData = flashObject.exportScreenshot();
if (screenshotData != null) {
// Set the screenshot image data as a base64 encoded data URI in the img src attribute
document.getElementById('screenshotObject').src = 'data:image/jpeg;base64,' + screenshotData;
// Set the screenshot img dimensions to match the Flash object tag.
document.getElementById('screenshotObject').width = flashObject.width;
document.getElementById('screenshotObject').height = flashObject.height;
document.getElementById('imageContent').style.visibility = 'visible';
}
}
function hideFlashScreenshot() {
document.getElementById('imageContent').style.visibility = 'hidden';
}
我正在使用Starling,因此我将wmode设置为direct。 Facebook隐藏并显示Flash对象,我只是将应用程序UI的当前状态绘制到'imageContent'元素中。
当回调显示为null时,Flash对象将保持隐藏状态。
我希望有人可以提供帮助,因为我在这个问题上已经有大约三天时间没有解决。