Facebook pass flashvars to swf?
Im trying to get the facebook use开发者_如何学JAVArname set to a flashvars and then pass it to a swf, like so:
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;
}
}
but the Name flashvars is showing up blank, is there another way to do this?
FB.api() is asynchronous, so you need to wait to show the SWF until it has responded.
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});
});
}
精彩评论