Official Facebook Actionscript API released!

On March 31 Facebook developers announced that Adobe and Facebook are working together to provide official support for building rich social applications in Flash.

You can read the full Josh Elman’s announcement at this link.

The new ActionScript 3.0 Client Library for Facebook Platform API, fully supported by Facebook and Adobe, makes it easy to build applications that combine the strengths of the Flash Platform and Facebook Platform.

Flash is available on more than 98% of Internet-connected PCs, so people can immediately access the applications, content, and video that enable social interactions. The Facebook Platform is used by millions of people everyday to connect and share with the people in their lives.

You can read more about it at this page.

Obviously I started playing with this new API, and I followed the instructions in the official tutorial Create your first Facebook application with Flex, changing a couple of things to make it work as I wanted.

This is the source code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" 
	backgroundColor="silver" backgroundImage=""
	applicationComplete="init()">
	<mx:Script>
		<![CDATA[
			import com.facebook.data.users.GetInfoData;
			import com.facebook.utils.FacebookSessionUtil;
			import com.facebook.data.users.FacebookUser;
			import com.facebook.data.users.GetInfoFieldValues;
			import com.facebook.commands.users.GetInfo;
			import com.facebook.net.FacebookCall;
			import com.facebook.events.FacebookEvent;
			import com.facebook.Facebook;
 
			private var fbook:Facebook;
			private var session:FacebookSessionUtil;
			private var user:FacebookUser;
 
			private function init():void{
				session=new FacebookSessionUtil("83ccead57ece4086338470a75e13c5b1","1fff6abf608e90e70e1aad07798aa8e4",loaderInfo);
				session.addEventListener(FacebookEvent.CONNECT,onConnect);
				fbook=session.facebook;
			}
			private function onLogin():void{
				this.removeChild(go_login);
				session.login();
			}
			private function onConfirmLogin():void{
				this.removeChild(loginbutton);
				session.validateLogin();
			}
			private function onConnect(e:FacebookEvent):void{
				var call:FacebookCall=fbook.post(new GetInfo([fbook.uid],[GetInfoFieldValues.ALL_VALUES]));
				call.addEventListener(FacebookEvent.COMPLETE,onGetInfo);
			}
			private function onGetInfo(e:FacebookEvent):void{
				user=(e.data as GetInfoData).userCollection.getItemAt(0) as FacebookUser;
				title.text="Hello "+user.first_name+" "+user.last_name+" born on "+user.birthday;
			}
		]]>
	</mx:Script>
 
	<mx:Label id="title" text="Facebook API test"/>
 
	<mx:Button id="go_login" label="Click here to login into Facebook" click="onLogin()"/>
	<mx:Button id="loginbutton" label="Click once logged into Facebook" click="onConfirmLogin()"/>
 
</mx:Application>

And this is the result:

As I am not a Flex maniac, I will fully explain (and improve) the script as soon as I’ll convert it to an AS3 class. Meanwhile I want you to focus on line 40 where I am getting information about the user.

The official page where you can get all the information about this process is this one.

Meanwhile, you can download the full source code with all needed libraries.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 3.50 out of 5)
Loading ... Loading ...
If you found this post useful, please consider a small donation.

14 Responses

  1. Prankard says:

    It doesn’t seem to be working for me. I login and have FB open in a new tab, then when I click the next button that validates my login the text still says “FaceBook API Test”.

    Is anyone else experiencing this?

  2. klikissy says:

    it’s the same for me… It does’nt work.

  3. Emanuele Feronato says:

    It works 4 me…

  4. ThomasTan says:

    cool feature! sad i don’t have a facebook acc and also don’t plan to make one, but advertising there seems sweet!

  5. dino says:

    I don’t get flex. Before you even get to the code, you have indented 3 times. Not my style.

  6. Prankard says:

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at prova/onGetInfo()[C:\Documents and Settings\Triqui\Desktop\provaflex\src\prova.mxml:39]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at com.facebook.net::FacebookCall/http://api.facebook.com/1.0/::handleResult()
    at com.facebook.delegates::WebDelegate/handleResult()
    at com.facebook.delegates::WebDelegate/onDataComplete()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()

  7. Emanuele Feronato says:

    You should click the 2nd button (the one saying “Click once…”) only when you get “You may now close this window and return to the application.” message on your FB page.

  8. [...] post contains a script made combining Official Facebook Actionscript API released! with Understanding Flash button component. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 [...]

  9. Alarik says:

    Hi,

    I just need a couple of info you may provide:

    I have a site completly built with Flash, I’d like to create a section in my site where any user can see (by providing facebook username&pwd) all his facebook data (including photos, events, posts, etc…)

    Do you think this is possible?

  10. dbomberg says:

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at prova/onGetInfo()[C:\Documents and Settings\Triqui\Desktop\provaflex\src\prova.mxml:38]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at com.facebook.net::FacebookCall/http://api.facebook.com/1.0/::handleError()
    at com.facebook.delegates::WebDelegate/handleResult()
    at com.facebook.delegates::WebDelegate/onDataComplete()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()

  11. EPerry says:

    Is there a way to avoid the confirmed logged in page. Like checking to see if a session exist without having to open a login window and just returning to the web app?

  12. vijay says:

    Hello
    Can i get the user Detail Without session.validateLogin()

  13. michele says:

    hi emanuele im michele from milano and im a newbe in flash develop. im trying to develop a facebook app with flex builder 4 and now I need to use a flash componet (.fla) in my flex application . Is this possible?

    PS: is possible to use flash builder to develop a facebook app?

    thanks,
    michele

  14. michele says:

    oops sorry in the PS i meant Flash professional, not flash builder

Leave a Reply