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:
  1. <?php
  2.  
  3.  
  4. require_once('facebook.php');
  5.  
  6. $facebook = new Facebook("your API key","your secret key");
  7.  
  8. $facebook_account = $facebook->require_login();
  9.  
  10. ?>
  11.  
  12. <div style = "padding:5px">
  13.     Hello <fb:name uid="<?php echo $facebook_account; ?>" useyou="false"/>!
  14. </div>
  15. <div style = "padding:5px">
  16.     Play Jamag!
  17. </div>
  18. <div style = "padding:5px;background-color:black">
  19. <fb:swf swfsrc="http://games.mochiads.com/c/g/jamag/jamag_secure.swf" swfbgcolor="#000000" wmode = "opaque" width="500" height="500" />
  20. </div>
  21. <div style = "padding:5px">
  22.     Find out how to embed your Flash games on Facebook (and much more) at <a href = "http://www.emanueleferonato.com">emanueleferonato.com</a>
  23. </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

Improve the blog rating this post
Tell me what do you think about this post. I'll write better and better entries.
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5 out of 5)
Loading ... Loading ...

» Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.

16 Responses to “Integrate your Flash game on Facebook”

  1. zedia.net on May 30th, 2008 8:43 pm

    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.

  2. Apples on May 30th, 2008 9:46 pm

    Thats incredible, great way to get more people to play your game!
    You think you can do that with myspace apps too?

  3. xavi on May 30th, 2008 11:10 pm

    thats cool. one problem though, I dont use facebook. lol =)

  4. Tony on June 1st, 2008 6:49 pm

    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!!

  5. Jonny-bee on June 2nd, 2008 7:37 pm

    Awsome stuff emanuele!! Worked a treat first time..

  6. Robert Kabwe on June 9th, 2008 5:58 am

    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:)

  7. microsheep on June 18th, 2008 11:57 am

    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?

  8. Jerry on June 25th, 2008 11:16 pm

    I followed this also and nothing works for me and Facebook has crap for information on why.

  9. Jerry on June 25th, 2008 11:26 pm

    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!

  10. Jerry on June 26th, 2008 8:19 pm

    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.

  11. vinod on July 12th, 2008 7:30 am

    This is really helpful for integration of flash game with facebook using php

  12. snipe on July 15th, 2008 11:31 pm

    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.

  13. SomeNick on August 9th, 2008 10:30 am

    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

  14. Goguigo on August 16th, 2008 6:57 pm

    Same problem as Jerry. Anyone knows a solution?

  15. gonzalo on September 10th, 2008 7:24 am

    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?

Leave a Reply




Trackbacks

  1. 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 [...]