Official Facebook Actionscript API released – AS3 version
2009-10-27 00:00:00 来源:WEB开发网This post contains a script made combining Official Facebook Actionscript API released! with Understanding Flash button component.
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.
本文示例源代码或素材下载
Tags:Official Facebook Actionscript
编辑录入:爽爽 [复制链接] [打 印]- ››ActionScript 2.0中的! 逻辑 NOT 运算符
- ››ActionScript 3.0 性能方面优化小知识整理收集
- ››Facebook的成功案例:社团群的经营
- ››Facebook开发者炮轰Android问题重重
- ››Facebook CEO痛批苹果iPhone:买了就后悔
- ››Facebook发布首款Android软件开发工具包
- ››Facebook 删除部分第三方 iPhone 应用证书
- ››Facebook 对新版 iPhone SDK 表示不满
- ››Facebook揭秘HipHop项目 PHP程序大提速
- ››Facebook 将重写 PHP 运行环境
- ››Official Facebook Actionscript API released –...
- ››ActionScript中文本字段的透明度缓动
赞助商链接