我试图将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, null, {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显示为空白,还有另一种方法吗?
答案 0 :(得分:0)
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, null, {name:response.name});
});
}