WEB开发网
开发学院图形图像Flash Official Facebook Actionscript API released –... 阅读

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{importflash.display.Sp

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

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接