问题描述
|
我试图将facebook用户名设置为flashvars,然后将其传递给swf,如下所示:
var flashvars = {
AppID: \"my_id\",Name: \"\"
};
function init()
{
FB.init({appId:APP_ID,status: true,cookie: true});
FB.getLoginStatus(handleLoginStatus);
}
function handleLoginStatus(response)
{
if (response.session) { //Show the SWF
FB.api(\'/me/\',function(response){ alert(response.name); flashvars[\'Name\'] = response.name;});
swfobject.switchOffAutoHideShow();
swfobject.embedSWF(\"main.swf\",\"ConnectDemo\",\"640\",\"480\",\"9.0\",null,flashvars,{name:\"ConnectDemo\"});
} else { //ask the user to login
var params = window.location.toString().slice(window.location.toString().indexOf(\'?\'));
top.location = \'https://graph.facebook.com/oauth/authorize?client_id=\'+APP_ID+\'&scope=\'+PERMS+\'&redirect_uri=\' + REDIRECT_URI + params;
}
}
但是名称flashvars显示为空白,还有另一种方法吗?
解决方法
FB.api()是异步的,因此您需要等待显示SWF,直到它响应为止。
if (response.session) { //Show the SWF
FB.api(\'/me/\',function(response) {
swfobject.switchOffAutoHideShow();
swfobject.embedSWF(\"main.swf\",\"ConnectDemo\",\"640\",\"480\",\"9.0\",null,flashvars,{name:response.name});
});
}