Facebook Flash 应用程序无法与 JavaScript 通信
我的index.php文件加载Facebook JavaScript SDK和FBJS桥:
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript" src="FBJSBridge.js"></script>
然后初始化Facebook SDK:
<script type="text/javascript">
FB.init({
appId : '<?=$fbconfig['appid']?>',
session: <?php echo json_encode($session); ?>,
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
并使用swfobject嵌入Flash文件:
swfobject.embedSWF("http://www.myserver.org/Facebook/app/app.swf", "holderDiv", "740", "616");
当我在服务器上运行此文件时,我可以通过ExternalInterface间接与Facebook JavaScript SDK通信我还可以使用 facebook-actionscript-api 直接从 ActionScript 启动相同的对话框。
然而,当我使用此索引文件作为 Facebook 画布 url 并在 Facebook iFrame 中加载 swf 时,通信会使应用程序崩溃。我不确定如何调试这个问题,但我认为这可能与跨域安全有关。欢迎任何有关调试和/或解决方案的想法。
My index.php file loads the Facebook JavaScript SDK and the FBJS bridge:
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript" src="FBJSBridge.js"></script>
It then inits the Facebook SDK:
<script type="text/javascript">
FB.init({
appId : '<?=$fbconfig['appid']?>',
session: <?php echo json_encode($session); ?>,
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
And embeds the Flash file using swfobject:
swfobject.embedSWF("http://www.myserver.org/Facebook/app/app.swf", "holderDiv", "740", "616");
When I run this file on my server, I can communicate with Facebooks JavaScript SDK either indirectly through ExternalInterface calls, launching various Facebook UI dialogs etc. And I can also use the facebook-actionscript-api to launch the same dialogs directly from ActionScript.
When I however use this index file as my Facebook canvas url and load the swf in a Facebook iFrame, the communication crashes the application. I'm not sure how to debug this but I think it might have to do with crossdomain security. Any ideas on debugging and/or solutions are welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
FBJSBridge.js 已在更新的 API 1.5 中被替换。现在它位于 AS3 源代码中。
The FBJSBridge.js has been replaced in the updated 1.5 of the API. It's now in the AS3 source.
看来添加参数allowScriptAccess:“always”就成功了。
奇怪的是,示例代码应用程序中没有提到这一点......
It seems adding the parameter allowScriptAccess: "always" did the trick.
Strange this isn't mentioned in sample code applications ...
在这里你可以找到一个带有源代码的教程 ===
与 Flash 和 javascript 通信
here u can find a tutorial with source coad ===
Communacation with Flash and javascript