Official Facebook Actionscript API released – AS3 version
This 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 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | package { import flash.display.Sprite; import fl.controls.Button; import flash.events.MouseEvent; import flash.text.TextField; 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; public class as3facebook extends Sprite { var my_text:TextField = new TextField(); var fbook:Facebook; var session:FacebookSessionUtil; var user:FacebookUser; public var button_labels:Array = ["Click here to login into Facebook","Click here once you logged in into Facebook"]; var my_button:Button; public function as3facebook() { addChild(my_text); my_text.width=460; my_text.x=20; my_text.y=100; my_text.text = "Facebook API test"; for (var i:int=0; i<2; i++) { my_button=new Button(); addChild(my_button); my_button.label=button_labels[i]; my_button.setSize(250,30); my_button.move(125, i*40+10); my_button.addEventListener(MouseEvent.CLICK, clickHandler); } session=new FacebookSessionUtil("83ccead57ece4086338470a75e13c5b1","1fff6abf608e90e70e1aad07798aa8e4",loaderInfo); session.addEventListener(FacebookEvent.CONNECT,onConnect); fbook=session.facebook; } function clickHandler(event:MouseEvent):void { switch (event.currentTarget.label) { case "Click here to login into Facebook" : onLogin(); break; case "Click here once you logged in into Facebook" : onConfirmLogin(); break; } } private function onLogin():void { session.login(); } private function onConfirmLogin():void { 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; my_text.text="Hello "+user.first_name+" "+user.last_name+" born on "+user.birthday; } } } |
And this is the result:
As in the Flex example, you should click the 2nd button (the one saying “Click here once…â€) only when you get “You may now close this window and return to the application.†message on your FB page.
I am really excited for this new API and I can’t wait to include it in a game.
Download the source code, with all required libraries
They can be easily customized to meet the unique requirements of your project.















(9 votes, average: 4.11 out of 5)









This post has 8 comments
ThomasTan
Cool, btw, i used my sis’s acc. :P
also, can you please show this on your blog and review it? please? thomastanck.googlepages.com
Anthony
I integrated that code with a game. It works when I test it locally. but it doesnt work when I import to my server on the web. and it doesnt work when its implemented into facebook either.
Anthony
Apparently, this code was meant for external applications. What if I want to connect using flash from within facebook. As in the application sits within the facebook websites. So there really is no necessary reason to ask for user login
dbomberg
also here I use debug version, get:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at as3facebook/onGetInfo()
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()
one giant media
Hi, thanks for the demo.
When I click the “login to facebook” button in the demo above, I get this error from the debug player:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at as3facebook/onGetInfo()
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()
Elia
Check your appkey and secretkey into class file
sunil
please help
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at as3facebook/onGetInfo()
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()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at as3facebook/onGetInfo()
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()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at as3facebook/onGetInfo()
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()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at as3facebook/onGetInfo()
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()
kunal
u r getting error becoz u r clicking the 2nd button without getting user info. so there is a simple solution that write a single line
i.e if(user!=null)
{
my_text.text=”dhsh”;
}
u will not get error.