Download Demo Files (Start & Completed versions for Part 1 & Part 2) In order for the completed code to work you have to put in your Facebook App ID and generated Facebook Social Plugin code in the required fields.
I would also recommend publishing for Adobe AIR 2.6 or 2.7. I have not tested this with AIR 3.0.
The use of the Facebook Like Button in Flash has been pretty difficult to produce. There have been some “work arounds” and “hacks”, but nothing as clear and direct as using the API’s from the ActionScript 3 SDK for Facebook Platform .
Now the ActionScript 3 SDK for Facebook Platform currently DOES NOT have any API’s that allow you to create the “Like” button, but using some other ActionScript API’s and a Facebook’s Social Plugin we can incorporate the “Like Button”.
- This example is publishing for Adobe AIR and not the Flash Player for the web.
- ActionScript 3 SDK for Facebook Platform currently does not have any API’s for the “Like Button”
There are two key components here to get started:
- Facebook Social Plugins - Facebook code snippets that allow you to incorporate Facebook social feature in your website without having to know any of the Facebook Graph APIs.
- Adobe AIR – HTMLLoader class - An Adobe AIR container that will display HTML content.
Create your “Like Button” Social Plugin
The Facebook Social Plugins allow you to quickly integrate your and/or other Facebook data into your HTML pages without having to know anything about the Graph API, FBML, etc. We are going to use the Facebook Social Plugin (let Facebook do the dirty work) and then plug the code into our AIR app.
- Visit: http://developers.facebook.com/docs/reference/plugins/like-box/
- Fill in your desired fields. You can use any public Facebook Page URL for the URL section. (eg. myNOTO (shameless plug), Adobe, FlashPlatform, etc)
- Click the “Get Code” button
- Click on “HTML5” and copy both sections of code to a new Dreamweaver document or blank document.
Create your HTML code
In order for the code to display in the HTMLLoader object, it must be placed in HTML.
- Create a new HTML5 document.
- Paste the “<div>” tag elements after the “<body>” tag.
- Change all double quotes to single quotes. This will allow the code to be used as one String in Flash.
- Add “https:” in front of ” //connect.facebook.net
You can copy and paste the code below. Change YOUR_APP_ID to your Facebook Application ID.
Incorporate your “LIKE” button into Flash (AIR Application) Download Demo Files (Start & Completed versions for Part 1 & Part 2)
- Open the file named “facebookNOTO.fla” from here.
- Save your file in your desired directory.
- You will notice: (these components will be used fully later in Part 2)
- Dynamic Text Field
- Text Area Component
- 5 buttons
- Create a Document class. File -> New -> ActionScript File
- Save the file in the same directory as your “.fla” and name it ‘NotoFB.as“ and it is CASE SENSITIVE!!!
This file(NotoFB.as) will be used as our Document Class for the facebookNOTO.fla file.
Create your document class (NotoFB.as)
Create the package, class definition and constructor function
Import the following classes that will be used in this example.
Define properties and initial values. The added code creates a new instance of the HTMLLoader class and defines the options and boundaries for the HTMLLoader object.
Create a function that will add the HTMLLoader object on the stage. Add the function the constructor function.
Paste the code that you copied from the Facebook Social Plugin Page.
After you paste your code, save your NotoFB.as file and return to Flash and set your class as the Document Class for your “.fla” file.
Test your movie. You will see the “distractor” animation. When you click on the “LIKE” button you will be prompted to log into Facebook.