home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / com / facebook / Facebook.as < prev   
Encoding:
Text File  |  2010-06-23  |  4.5 KB  |  141 lines

  1. package com.facebook
  2. {
  3.    import com.facebook.commands.auth.ExpireSession;
  4.    import com.facebook.delegates.IFacebookCallDelegate;
  5.    import com.facebook.events.FacebookEvent;
  6.    import com.facebook.net.FacebookCall;
  7.    import com.facebook.session.IFacebookSession;
  8.    import flash.events.EventDispatcher;
  9.    import flash.net.URLRequest;
  10.    import flash.net.navigateToURL;
  11.    
  12.    use namespace facebook_internal;
  13.    
  14.    public class Facebook extends EventDispatcher
  15.    {
  16.       public var waiting_for_login:Boolean;
  17.       
  18.       protected var _currentSession:IFacebookSession;
  19.       
  20.       public var connectionErrorMessage:String;
  21.       
  22.       public function Facebook()
  23.       {
  24.          super();
  25.       }
  26.       
  27.       public function post(param1:FacebookCall) : FacebookCall
  28.       {
  29.          var _loc2_:IFacebookCallDelegate = null;
  30.          if(this._currentSession)
  31.          {
  32.             param1.session = this._currentSession;
  33.             param1.facebook_internal::initialize();
  34.             _loc2_ = this._currentSession.post(param1);
  35.             param1.delegate = _loc2_;
  36.             return param1;
  37.          }
  38.          throw new Error("Cannot post a call; no session has been set.");
  39.       }
  40.       
  41.       public function startSession(param1:IFacebookSession) : void
  42.       {
  43.          this._currentSession = param1;
  44.          if(this._currentSession.is_connected)
  45.          {
  46.             dispatchEvent(new FacebookEvent(FacebookEvent.CONNECT,false,false,true));
  47.          }
  48.          else
  49.          {
  50.             this._currentSession.addEventListener(FacebookEvent.CONNECT,this.onSessionConnected);
  51.             this._currentSession.addEventListener(FacebookEvent.WAITING_FOR_LOGIN,this.onWaitingForLogin);
  52.          }
  53.       }
  54.       
  55.       public function grantExtendedPermission(param1:String) : void
  56.       {
  57.          navigateToURL(new URLRequest("http://www.facebook.com/authorize.php?api_key=" + this.api_key + "&v=" + this.api_version + "&ext_perm=" + param1),"_blank");
  58.       }
  59.       
  60.       public function refreshSession() : void
  61.       {
  62.          this._currentSession.refreshSession();
  63.       }
  64.       
  65.       public function logout() : void
  66.       {
  67.          var _loc1_:ExpireSession = new ExpireSession();
  68.          _loc1_.addEventListener(FacebookEvent.COMPLETE,this.onLoggedOut,false,0,true);
  69.          this.post(_loc1_);
  70.       }
  71.       
  72.       public function get api_version() : String
  73.       {
  74.          return !!this._currentSession ? this._currentSession.api_version : null;
  75.       }
  76.       
  77.       protected function onLoggedOut(param1:FacebookEvent) : void
  78.       {
  79.          if(param1.success == true)
  80.          {
  81.             this._currentSession.session_key = null;
  82.          }
  83.          dispatchEvent(new FacebookEvent(FacebookEvent.LOGOUT,false,false,param1.success,param1.data,param1.error));
  84.       }
  85.       
  86.       protected function onWaitingForLogin(param1:FacebookEvent) : void
  87.       {
  88.          this.waiting_for_login = true;
  89.          dispatchEvent(new FacebookEvent(FacebookEvent.WAITING_FOR_LOGIN));
  90.       }
  91.       
  92.       public function login(param1:Boolean) : void
  93.       {
  94.          this._currentSession.login(param1);
  95.       }
  96.       
  97.       public function get secret() : String
  98.       {
  99.          return !!this._currentSession ? this._currentSession.secret : null;
  100.       }
  101.       
  102.       public function grantPermission(param1:Boolean) : void
  103.       {
  104.          var _loc2_:String = "http://www.facebook.com/login.php?return_session=" + (param1 ? 1 : 0) + "&api_key=" + this.api_key;
  105.          navigateToURL(new URLRequest(_loc2_),"_blank");
  106.       }
  107.       
  108.       public function get is_connected() : Boolean
  109.       {
  110.          return !!this._currentSession ? this._currentSession.is_connected : false;
  111.       }
  112.       
  113.       public function get session_key() : String
  114.       {
  115.          return !!this._currentSession ? this._currentSession.session_key : null;
  116.       }
  117.       
  118.       public function get uid() : String
  119.       {
  120.          return !!this._currentSession ? this._currentSession.uid : null;
  121.       }
  122.       
  123.       protected function onSessionConnected(param1:FacebookEvent) : void
  124.       {
  125.          var _loc2_:IFacebookSession = param1.target as IFacebookSession;
  126.          dispatchEvent(param1);
  127.       }
  128.       
  129.       public function get api_key() : String
  130.       {
  131.          return !!this._currentSession ? this._currentSession.api_key : null;
  132.       }
  133.       
  134.       public function get expires() : Date
  135.       {
  136.          return !!this._currentSession ? this._currentSession.expires : new Date();
  137.       }
  138.    }
  139. }
  140.  
  141.