Creating a Flash Facebook application with the Facebook Actionscript API

It’s time to see how can we build a Flash Facebook application.

What we are going to do is a Flash movie to be embedded in a Facebook application, able to interact with the user by publishing notes and stories on the wall.

The first thing we need is the official Facebook Actionscript API. This library contains all we need to create a complete Facebook Flash application.

You can download the source code at this link, but before messing with AS3, let’s create the PHP part.

I suggest you to read the Developing a Facebook Application for absolute beginners posts from 1 to 5 if you don’t know how to create a basic Facebook application.

Then, take a look at the PHP code:

Notice at lines 1-3 the way you can import CSS style sheets. Don’t forget to use htmlentities on the imported file.

Then, at lines 5-9 I created a simple javascript function called grant that just redirects the browser to the application page. That is, basically it refreshes the page, and it will be called once the user will grant (or won’t grant) the permission to publish contents on his wall by submitting the permission form as you can see at line 30.

This is possible thanks to next_fbjs="grant()".

Another important thing in this script you should arleady know is the way I ask for publishing permission.

You can ask for permission inside the Flash movie itself but I found it easier to ask directly from Php. This way, you can even hide the Flash movie if the user does not grant permissions.

But the core of the script, the think you did not see in previous tutorials is the way I include the Flash movie at line 34 with the fb:swf tag.

You can find the official documentation at this page, and the most interesting thing is Facebook is passing some interesting parameters to the movie.

Let’s see the Actionscript now… I used the button component to create the buttons but this is not important… here it is the commented script:

The interesting thing of this script is the way you can send notifications (line 44) and publish posts (line 49)… I won’t talk about notifications because Facebook will deprecate this method in late November/early December 2009 , but I want you to look at the way I publish the post following the format explained at the official attachment docs.

You can test the application at this page and download the full source code, library included.

Next time, we’ll see how to add more functions.

  • Is’nt this a security risk when you put the secret key in the swf?

  • NEVER PUT YOUR SECRET KEY IN UR SWF, NEVER. Emenuelle, great post, I made a game for facebook, it called Snaker ( I would like to write a post in your blog about it, if you’ll like. I used PHP for the whole backend (instead of using the Actionscript library), and used AMFPHP to communicate between the flash and PHP. I’ll send you an email about it. It would be great honor to write a tutorial in your blog ;)

    • sankar

      Hi friend i need code.Can u send me please.
      i am willing to create app for facebook

  • Did you use Flex or the Flash IDE?

  • Pingback: Websitemarketingbiz.Net- Hyprobulksms-Rahsia Jana Income mudah » Blog Archive » Creating a Flash Facebook application with the Facebook …()

  • Pingback: Down the Foxhole – News Flash()

  • @Yarden Refaeli: Yeah thats what I thought and why I’am asking. :)
    How do you Auth the app in facebook? WIth php or with JavaScript

  • brew


    You make the best tutorials on the web.

    How about a tutorial on making a friend selector to select which friend to send a message to.

    thanks again for a really useful tutorial!

  • Pingback: Weekly Shared Items – 10. November, 2009 | TOXIN LABS - weblog of a german design student from wuerzburg()

  • Pingback: Creating a Flash Facebook application with the Facebook Actionscript API – part 2 : Emanuele Feronato()

  • Pingback: ??Facebook??????????? | God is not home today()

  • Pingback: Emanuele Feronato()

  • Hi all! I’m kind ned help here..I was planning to do a facebook application using flash as my Final Year Project..need help for ideas. I’m looking for small scale,complete and interactive application. Last but not least, is it a ‘must’ to use CSS and php? I’m just beginner in flash and zero knowledge in php and css but I really2 wanted to learn in this field…hope u guys can help me here..

  • robi2216

    Hi your tutorial is great!!!!

    I used the SendMail but I donĀ“t worked, please if you could help me in this case

    case “Send EMail” :
    fbcall = new SendEmail([uid], ‘Hi’, ‘Facebook is excelent’, ‘Hi‘);;


  • Hi nice tutorial,

    i am trying to use share element to share swf from Publish data.
    can you help me to that.


  • Your tutorial is great, but your sample has the same problem I do with the posting of an item. It requires the user to approve all publications… most facebook users don’t want to do that. Do you know how to make it display the Feed Form for approval on Each post?

    Thanks in advance

  • Markham Butler

    This is great stuff. In your tut, you say, “You can ask for permission inside the Flash movie itself but I found it easier to ask directly from Php.” Can you point me to info on how to ask permissions from within Flash?

  • Finally, a decent tutorial the flash IDE. Thanks a lot for that.

    I have pretty much the same questions as everyone else.

    – First, how to authorize from within facebook.
    – Second, What about the publish this post popup , I don’t want to send messages to my users without asking them :)

    Would really appreciate the help

  • Pingback: MoMo-Studio Development Blog » Blog Archive » Zetta Monster Plus….Facebook?()

  • kanyal

    there is new tab or window open problem with this api app, how you solved it. can we test this app on desktop pc and when finished can be hosted on web. i am not talking for desktop app. i am asking about facebook web app. hope you will get idea what i want to clear

  • gujarathi

    I am facing a problem in following code. I want my application and login screen should open in same browser window. Using this code It always opens in new window. Will anybody please tell me how to achieve it?
    Again the code in if/else block in the function Init() never gets executed. It directly goes to session.login() and opens new window.

    Please help me.

    public function Init():void
    session = new FacebookSessionUtil(“MY_API_KEY”,”MY_SECRET_KEY”,loaderInfo);
    session.addEventListener(FacebookEvent.CONNECT, handle_Connect);
    trace(“initial login”);
    if(loaderInfo.parameters.fb_sig_added == true)
    else if(loaderInfo.parameters.fb_sig_added == false)
    navigateToURL(new URLRequest(“” +loaderInfo.parameters.fb_sig_api_key), “_top”);

    public function handle_Connect(event:FacebookEvent):void
    var call1:FacebookCall = GetInfo([fbook.uid],[GetInfoFieldValues.ALL_VALUES]));
    public function onConfirmLogin():void
    public function handle_getinfoComplete(event:FacebookEvent):void
    user=( as GetInfoData).userCollection.getItemAt(0) as FacebookUser;
    if( user == null )
    trace(“hi”,user.first_name+” “+user.last_name);



  • EZ

    Encountered a problem:
    My Flash movie is not loaded from my server (“Movie not loaded…”).

    Trying to debug the problem I’ve added Emanuele’s SWF to mine:

    The result:
    The SWF from loads just find
    The SWF from does not load

    Permission problems?
    Any ideas?

    Trying to reach this swf from the browser works just fine:

  • xoxo

    hi could you please create a tutorial about loading friends that uses the application in facebook, take a look at this link:

    below the game you could see those people who is using the application. then it is limit to 8 friends to be viewed

    Been trying to google around about this, and basically i really don’t have any idea how to do this one. :D

  • sankar

    I need Line by line explanation for the above sorry for asking this because i don’t get much details in face book means nuts i need from u guys please help me.

  • sankar

    i asked explanations for face book API classes not for this tutorial.sorry for my poor way of communication.

    I need to get and post the image to Facebook. is it possible. please i am waiting for all ur valuable replies. thanks in advance

  • nice tutorial, this very helpful.. i want to integrete my game to facebook

  • karunakar

    nice tutorial. Helped me a lot……..Thank u very much

  • fuck off ur tutorial it doens not work you just take the exemple of the as3 api liarrrrrrrrrrrr, dude put some good code in ur exemple and stop puting shit, make ur variable having type

  • I am newbies to Flash and I used CS4
    I want to build flash app for facebook game
    i searched it and just found out in ur side

    A great help –

  • Karthik

    I’m very new Facebook applications.
    I’m trying to develop a flash game application on facebook.
    Please provide me with some sample code.
    That would be great helpfull for me.
    Thanks in advance.

  • I want to get Facebook user id in action script ? could you provide me with a sample ?!

    Thanks a lot.

  • Jaz

    hello, we are now in our Capstone Project and we would like to create an application for facebook. My friend said that facebook application in flash is great… can you guide me :)) thank you so much ^__^

  • The flash demo page does not work anymore. Any other link where we could see it in action?

  • Pingback: Technological Specifications | mmmmppp()

  • Pingback: Prospectus | mmmmppp()

  • Luzmar

    hello!!! im trying to do a flash website (facebook) i would like to know if any of you can help me with that

  • Davai

    I’m trying to figure out how companies that are using flash to build facebook apps are able to Cloak the files from the users.

    eg. Several of the Zygna games are completely Flash, presumably a SWF file sitting on their end – but unlike the typical flash game, we can’t simply pull the link to the SWF and save the entire thing to our computer.

    Any suggestion on where I would begin learning how to do this (cloaking the components, not stealing someone else’s)