Echoes of Burma Jones Design/Developer Blog
ABOUT
"Echoes of Burma Jones" is a blog dedicated to the work, and happenings of Ted Perez + Associates. For our full web portfolio, please check out our main site.
LINKS
TED PEREZ + ASSOCIATES   
RECENT POSTS
Career Opportunities at Ted Perez + Associates
Cocktail of the Week: Daiquiri
Art-Spire's Best 100 Digital Agencies in the World
Cannes Bronze Cyber Lion Winner: Sprint NOW Clock
Cocktail of the Week: Manhattan
Adobe CS5 Student Hub
Cocktail of the Week: Tom Collins
2009 Holiday Gift
Cocktail of the Week: The House Margarita
Webby Winner: Sprint's NOW Widget Media
POSTED BY
POSTS BY GENERALPOSTS BY CAPTAINPOSTS BY ARTISANPOSTS BY PIONEER
CATEGORIZED POSTS
3D
After Effects
Animation
AS3
Awards
Cocktail of the Week
Design
Flash
General
Out of State
Ted Perez Artifact
This Date in History
Video Production

September 25, 2009

Facebook Connect in Flash (ActionScript 2)

FILED UNDER: Flash

This article will provide everything needed to get a small Facebook Connect related site up and running using Flash (AS2). Needs: Flash MX or newer, text editor and a web server to place files.  DOWNLOAD SOURCE

images/imax_dos.jpg

Why Facebook Connect?

Facebook Connect allows a site's users to access relevant data [e.g. friends, photos and posts] directly on your site and allow the user to post directly to Facebook without leaving your site. The principal point is to extend your site's reach organically by providing users with an easy and effective way to share. Greater detail provided by Facebook in smart-sounding tech talk and marketing speak.

How does it work?

The first step is enabling users to log-in to their Facebook account without leaving your site – via Facebook Connect. Users will either be asked to “allow” your site to access their Facebook information [if previously logged in] or log-in through a Facebook prompt [if not previously logged in]. It is important to keep in mind, as a general user and not a developer, that you will see a much higher rate of adoption/allowance if the content is compelling, promise is plausible and/or messaging clear [shoot for all three where possible]. Once a user has confirmed that your site has access to their Facebook account they will not be prompted again until they log out of Facebook.

Setup Facebook Connect Application

Before your site can access any part of Facebook you will need to create an application. Do not be intimidated by Facebook’s keg of questions, the only items that are absolutely necessary are:

images/imax_connect_settings.jpg

HTML/JavaScript Setup

You can find all the following files with some demo code in the demo ZIP.

  1. Place the xd_receiver.htm in the root directory of your Facebook Connect site.
  2. Link to Facebook JavaScript API.
  3. Create an fb_connect.js file (or whatever you want to name the JavaScript file that interacts with Flash/Facebook) and include that in your HTML file.
  4. Make sure your CSS settings and Flash parameters are in order (z-index:0 and wmode:transparent).
  5. Add delays on multiple JavaScript calls to handle browser related bugs (specifically IE6).

Logging In/Logging Out

With that, you’re set up. Let’s see it in action. You should see scrims like the following when testing the login/logout functionality.

images/imax_tres.jpg

images/imax_ocho.jpg

images/imax_seis.jpg

Flash and Facebook: ExternalInterface Call

Next, you will need to allow your Flash movie to access the JavaScript setup in the previous step. Add the following to your Flash movie....

import flash.external.ExternalInterface;
ExternalInterface.addCallback("returnProfile", this, returnProfile);
ExternalInterface.addCallback("returnFriends", this, returnFriends);
ExternalInterface.addCallback("returnLogoutStatus", this, returnLogoutStatus);

var fbUser;
var fbFriends;
var isLoggedIn:Boolean = false;

function checkConnect(){
getURL("javascript:checkConnect();");
}
function loginConnect(){
getURL("javascript:loginConnect();");
}
function logoutConnect(){
getURL("javascript:logoutConnect();");
}
function returnLogoutStatus(){
isLoggedIn = false;
btnLoginFB.tf.text = "LOGIN";
}
function returnProfile(userInfo) {
isLoggedIn = true;
btnLoginFB.tf.text = "LOGOUT";
fbUser = userInfo[0];

}
function returnFriends(friendInfo) {
fbFriends = friendInfo;
fbFriends.sortOn(["is_app_user","name" ], [Array.DESCENDING | Array.NUMERIC, Array.CASEINSENSITIVE]);
fbFriendCount = fbFriends.length;
}

 

Creating Feed

One of the most useful [and oddly frustrating] aspects of working with the Facebook sytem is creating a "Feed Template" so your users can post to their feed. There are ways to generate Feed Templates through code (Facebook demo app has example) or go through the Facebook Developer Tool. If using the tool, make sure to note the "Template Bundle ID" after clicking on the "Register Template Bundle" button. If you don’t - and this is not an exaggeration, Facebook will pluck every feather of a dozen chickens and mail you the feathers, COD of course, in packing tube. Do it. We have received such a package and believe us when we say that a lot of pressure and a lot of feathers creates quite a mess when opened.

Posting to Feed

With the feed setup, you simply need to add a few lines of code to prompt the "post to feed" scrim.

images/imax_quatro.jpg

images/imax_cinco.jpg

images/imax_siette.jpg

Conclusion

Facebook Connect has added a sharing wrinkle that is most definitely worth investigating and given the relative ease of set-up, now is definitely the time to jump in and take full advantage of it before some other developer tries to piss in your punch. Good luck!

DOWNLOAD SOURCE

14 RESPONSES TO "Facebook Connect in Flash (ActionScript 2)"
Joe SAYS:
Tuesday 07/09/10 @ 06:45AM
Hi can some one help me understand what problem this statment helps to solve. I'm having problems getting facebook connect to work on IE 6 and believe it to be related. "Add delays on multiple JavaScript calls to handle browser related bugs (specifically IE6)."
 
rombout versluijs SAYS:
Wednesday 14/07/10 @ 09:59AM
Hi thanks for this app. but i sont understand how i can post feeds with this app. I want to add this to a site which has different kinds of events. so how do i add feeds/ events to this system. i cant seem to find the "post feed" help is appreciated
 
Az SAYS:
Wednesday 05/05/10 @ 02:01AM
Hi, I find your post being really good and helpful. However, after downloading the source, I cant seem to get it running properly from the server. Secondly, I cant open the .FLA file in any Macromedia nor Adobe Flash softwares. Look forward to hear from you. Cheers.
 
shoei SAYS:
Thursday 25/03/10 @ 03:34AM
Hi, first of all I would like to thank you for this tut. Connection works out fine, but now i would like to know how the facebook comment box is going to show up after logging in? could you please help me? Thank you very much in advance.
 
DesignFission SAYS:
Monday 22/03/10 @ 11:51PM
Hi, I was wondering if I can enhance on your code and share it on my blog with credits. I couldnt find your email, so I'm leaving a comment here.
 
DesignFission SAYS:
Monday 22/03/10 @ 06:59PM
Thanks for sharing this. Saved me a lot of time to start developing Flash apps to be integrated with FB!
 
sedemonkey SAYS:
Monday 18/01/10 @ 07:04PM
The "Unexpected File Format" error does indeed have to do with running a CS3 file in CS4. The Internet Explorer issue can be fixed by adding a delay to the function calls. Once I get a little bit I will post a fix.
 
Andrew SAYS:
Thursday 10/12/09 @ 07:33AM
Well, it seems to work with internet explorer... but only after you hit the login button 5 times... Does anyone else experience lag-time?
 
Andrew SAYS:
Thursday 10/12/09 @ 07:31AM
Also... this does not work with internet explorer...?
 
Andrew SAYS:
Wednesday 09/12/09 @ 11:20AM
Also, @Rutger, @ED, you need to download CS4 and convert the document to CS3 to edit it...
 
Andrew SAYS:
Wednesday 09/12/09 @ 11:19AM
Hey, Thanks for the sample. I uploaded it, tested it, and I found that "CheckConnect" is doing nothing... Everything else works fine, but the initial CheckConnect does not work.
 
Ed SAYS:
Sunday 22/11/09 @ 06:46PM
I'm also getting the same issue as RUTGER, when I try to open up the FLA i get 'Unexpected File Format'.
 
Rutger SAYS:
Wednesday 18/11/09 @ 03:14AM
This is exactly what I need, but the main.fla gives an 'Unexpected File Format' in Flash.. :(
 
John SAYS:
Wednesday 14/10/09 @ 09:09PM
I just wanted to thank you for this extremely helpful post. Its very well structured and easy to understand. There is so much information out there regarding Facebook connect and Facebook application development, but this by far have been the most helpful post I've seen.

LEAVE A COMMENT

NAME:EMAIL: (NOT PUBLISHED)*WEBSITE:
COMMENT:
BOT-BUSTER 3000 SECURITY CODE:
(*) = REQUIRED



0 posts found