/ Published in: ActionScript 3
Using the Facebook AS3 library to authenticate in a Flex Mobile View
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?xml version="1.0" encoding="utf-8"?> <s:View xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" title="FacebookAuthView" backgroundAlpha="0" actionBarVisible="false" viewActivate="view1_viewActivateHandler(event)" removing="view1_removingHandler(event)" creationComplete="view1_creationCompleteHandler(event)"> <fx:Script> <![CDATA[ import com.facebook.graph.FacebookMobile; import mx.events.FlexEvent; import spark.events.ViewNavigatorEvent; import vo.Profile; private var thisProfile:Object; private var facebookWebView:StageWebView; override public function set data(value:Object):void { thisProfile = value as Profile; } override public function createReturnObject():Object { return thisProfile; } protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void { facebookWebView = new StageWebView(); facebookWebView.viewPort = new Rectangle(0,0,stage.width,stage.height); var permissions:Array = ["publish_stream"]; FacebookMobile.login(onLogin,this.stage,permissions,facebookWebView); } private function onLogin(success:Object,fail:Object):void { thisProfile.facebookConnected = true; // navigator.popView(); } protected function view1_removingHandler(event:ViewNavigatorEvent):void { facebookWebView.dispose(); } protected function view1_creationCompleteHandler(event:FlexEvent):void { FacebookMobile.init("your dev key here",onLogin); } ]]> </fx:Script> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> </s:View>