Facebook Auth View


/ Published in: ActionScript 3
Save to your folder(s)

Using the Facebook AS3 library to authenticate in a Flex Mobile View


Copy this code and paste it in your HTML
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
  3. xmlns:s="library://ns.adobe.com/flex/spark"
  4. title="FacebookAuthView"
  5. backgroundAlpha="0" actionBarVisible="false"
  6. viewActivate="view1_viewActivateHandler(event)"
  7. removing="view1_removingHandler(event)"
  8. creationComplete="view1_creationCompleteHandler(event)">
  9. <fx:Script>
  10. <![CDATA[
  11. import com.facebook.graph.FacebookMobile;
  12.  
  13. import mx.events.FlexEvent;
  14.  
  15. import spark.events.ViewNavigatorEvent;
  16.  
  17. import vo.Profile;
  18.  
  19. private var thisProfile:Object;
  20. private var facebookWebView:StageWebView;
  21.  
  22. override public function set data(value:Object):void
  23. {
  24. thisProfile = value as Profile;
  25. }
  26.  
  27. override public function createReturnObject():Object
  28. {
  29. return thisProfile;
  30. }
  31.  
  32.  
  33. protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
  34. {
  35. facebookWebView = new StageWebView();
  36. facebookWebView.viewPort = new Rectangle(0,0,stage.width,stage.height);
  37. var permissions:Array = ["publish_stream"];
  38. FacebookMobile.login(onLogin,this.stage,permissions,facebookWebView);
  39. }
  40.  
  41. private function onLogin(success:Object,fail:Object):void
  42. {
  43. thisProfile.facebookConnected = true;
  44. // navigator.popView();
  45. }
  46.  
  47. protected function view1_removingHandler(event:ViewNavigatorEvent):void
  48. {
  49. facebookWebView.dispose();
  50. }
  51.  
  52. protected function view1_creationCompleteHandler(event:FlexEvent):void
  53. {
  54.  
  55. FacebookMobile.init("your dev key here",onLogin);
  56. }
  57.  
  58. ]]>
  59. </fx:Script>
  60. <fx:Declarations>
  61. <!-- Place non-visual elements (e.g., services, value objects) here -->
  62. </fx:Declarations>
  63. </s:View>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.