Integrate your Flash game on Facebook
You all should know Facebook. I think it would be interesting to integrate your Flash game into a Facebook application.
There are more options than you can imagine, but at the moment I'll just embed a game, nothing more. Just remember there will be a lot more.
Obviously, first you have to have a Facebook account and be logged in
Then you have to install the Developer application.
From this page http://developers.facebook.com/get_started.php click on "Add Facebook Developer Application" and you will be able to start creating your own applications.
Once you clicked on that link, you will find a "Developer" item in the left nav button. This is your application control panel, where you can manage your applications.
Click on "Set up New Application"

You will be redirected to a quite unclear page with a lot of fields to fill... don't worry, you will be out of this step in less than 2 minutes.
Just follow this picture:

Let me explain the most important fields:
Application name: This is the name of your application
Developer Contact E-mail: The email Facebook will use to contact you if there are any problems or important updates
User Support E-mail: Users will be able to mail you at this address
Callback URL: Very important, it's the URL of the application on your server. That's the place where you will write your application
Canvas Page URL: Another very important field... this is the URL of your Facebook application... the one you will share. It's very importat than you choose an URL long at least 7 chars or you won't be able to submit the form and you will lose all your previously inserted data!
Leave Use FBML checked. FBML stands for FaceBook Markup Language and enables you to build full Facebook Platform applications that deeply integrate into a user's Facebook experience.
In four words, another language to learn
Application Type must be Website because we are going to embed a web game, and be sure to check Yes on Can your application be added on Facebook? to enable more options
Select Smart size on Default Iframe Canvas Size Option and check Users and All Pages on Who can add your application to their Facebook account?
Application Description: Write here how awesome is your game
Default Profile Box Column: Wide
Side Nav URL: write the same as Canvas Page URL
And you finished this step! You'll notice you left a lot of blank fields, but at the moment we want to quickly embed a game into Facebook so never mind... you'll learn how to fill the entire form later
Click on Submit and you will be redirected to this page:

Write down both API key and Secret values
Now it's time to write some lines of code into your server.
From the Facebook resources page download the PHP (4 and 5) Client Library and uncompress it in the directory you specified in the Callback URL, then create an index.php file with this code:
-
<?php
-
-
-
require_once('facebook.php');
-
-
$facebook = new Facebook("your API key","your secret key");
-
-
$facebook_account = $facebook->require_login();
-
-
?>
-
-
<div style = "padding:5px">
-
Hello <fb:name uid="<?php echo $facebook_account; ?>" useyou="false"/>!
-
</div>
-
<div style = "padding:5px">
-
Play Jamag!
-
</div>
-
<div style = "padding:5px;background-color:black">
-
<fb:swf swfsrc="http://games.mochiads.com/c/g/jamag/jamag_secure.swf" swfbgcolor="#000000" wmode = "opaque" width="500" height="500" />
-
</div>
-
<div style = "padding:5px">
-
Find out how to embed your Flash games on Facebook (and much more) at <a href = "http://www.emanueleferonato.com">emanueleferonato.com</a>
-
</div>
Line 3: Don't display errors. With Php4 I got a couple of warnings, so I decided to remove them
Line 5: Including the facebook.php file you previously downloaded from the Facebook resources page
Line 7: Creating a new Facebook class. Be sure to insert your API key and Secret values you wrote down previously
Line 9: Force the user to login and save his data on $facebook_account variable
Line 14: First FBML tag: fb:name renders the name of the user specified, optionally linked to his or her profile.
The uid attribute is the id of the user name you want to show. In this case, the one saved in the $facebook_account variable
The useyou attribute is set to false because I want to display the name and not "you"
Line 20: Second FBML tag: fb:swf renders a Flash movie
swfsrc is the absolute URL of the Flash movie
swfbgcolor is the background color of the movie
wmode specifies if the Flash movie is transparent, opaque or window. If you set it to transparent, you will override the swfbgcolor attribute
And that's it!!! Now go to http://apps.facebook.com/jamag_game/ to play Jamag on Facebook.
What's so interesting in this?
Well, first of all you created a Facebook application, and that makes you a Facebook application developer.
Second, and more important, Facebook passes some interesting parameters to the SWF when it is loaded... and could make your game viral... I am going to mess around a bit and write a new tutorial soon.
Meanwhile, don't forget to play Jamag on Facebook
Tell me what do you think about this post. I'll write better and better entries.
They can be easily customized to meet the unique requirements of your project.
16 Responses to “Integrate your Flash game on Facebook”
Leave a Reply
Trackbacks
-
Links for integrating Flash and Facebook | Psyked on
June 17th, 2008 6:31 pm
[...] Integrate your Flash game on Facebook (Emanuele Feronato) June 17, 2008 | In Flash | No Comments [...]


I have been trying to add your game on my facebook page but I can’t seem to find how. It would be cool if you could add a flash game to your personal page.
Thats incredible, great way to get more people to play your game!
You think you can do that with myspace apps too?
thats cool. one problem though, I dont use facebook. lol =)
Hi Emanuele - I’ve followed your guide to adding a Flash game on Facebook, but I’m running into probelms. Can you please contact me to run through your instructions? Thanks!!
Awsome stuff emanuele!! Worked a treat first time..
Thanks Emanuele for taking the time to post the instructions. I finally sat down and followed your tutorial and have my first working facebook game:)
Great tutorial, Emanuele!
I’ve ran into one problem, though:
I’ve published my game both on my site and in Facebook (in both cases it is the same SWF).
It seems that when someone enters the Facebook leaderboard, it doesn’t reflect on the leaderboard on my site and vice versa…
As if these are 2 different leaderboards…
I’ve noticed that it doesn’t happen with your game…
http://www.microsheep.com/index.php?option=com_content&view=category&layout=blog&id=2&Itemid=4
http://apps.facebook.com/micro_olympics_mars/
Any ideas?
I followed this also and nothing works for me and Facebook has crap for information on why.
Here is what I am getting when I finished posting all the info and making the index.php page.
The URL http://thepixelcastle.com/ladybug returned HTTP code 200 and no data.
There are still a few kinks Facebook and the makers of Ladybug are trying to iron out. We appreciate your patience as we try to fix these issues. Your problem has been logged - if it persists, please come back in a few days. Thanks!
I wasn’t able to use PHP for some reason to get it to work but I did get HTML to work just not any of the FBML.
This is really helpful for integration of flash game with facebook using php
Any ideas on integrating Google Analytics to track Flash activity within Facebook? If we try to embed the tracking tags within Flash, set to communicate back to the canvas page, using something like”
getURL(”javascript:pageTracker._trackPageview(’/myflashapplication/
button1′)”)
We’re getting a Facebook sandbox permission error.
Very straightforward tutorial. I have begun to mess around with FaceBook applications myself. And while slowly making progress, its a total headache! I have never had to fix so many bugs in such a short period of time before in my life… heh :P
Same problem as Jerry. Anyone knows a solution?
i am planning on putting a game on facebook and creating a scoreboard, buy i dont know how to connect flash with MySQL…any help there?