This is a fairly general problem I am having here, so I figured I would ask, hopefully someone can help me out.
I have a flex app using the facebook js bridge to log in, and I am trying to pass the users name back to the app, but I am coming across the thing that I will explain after the code:
function getFriends() {
var nameOfPlayer = "";
FB.api('/me', function(response) {
nameOfPlayer = response.name;
});
return nameOfPlayer;
}
If I have my flex app print nameOfPlayer, it returns undefined, same as if I do an alert with nameOfPlayer, but if I do an alert inside of the FB.api call for nameOfPlayer, then it will pop up with my name, but it still won’t return name. I tried having it return a general string, and that works, so it is passing the information over, it just isn’t saving to the variable. Any idea how to fix this? This is probably very convoluted, so if I need to clarify anything let me know. Thanks in advance for any help you can give me 🙂
You should be doing this in an event-driven way. Some pseudo-code is written below to get you started.
In your facebook api class: