SWF является нулевым API Graph Facebook и библиотекой ActionScript 3 - PullRequest
0 голосов
/ 15 февраля 2011

Я получаю 'swf is null' в консоли Firebug при вызове Facebook.login (handleLogin, {perms: "user_photos, publish_stream"}) с помощью API API Facebook Actionscript 3 1.5 Graph.Не уверен, в чем проблема, но вот код AS3:

  package alvincrespo
  {
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.external.ExternalInterface;
    import flash.text.TextField;
    import fl.controls.Button;
    import flash.utils.Timer;
    import flash.events.TimerEvent;

    //-----------------------
    //Facebook Classes
    import com.facebook.graph.Facebook;
    import com.facebook.graph.data.FacebookSession;
    import com.facebook.graph.net.FacebookRequest;
    //-----------------------

    public class Main extends MovieClip
    {

      public var btn_login              :Button;
      public var txt_status             :TextField;
      private var APP_ID                :String = ""; //put in the app id here


      public function Main():void
      {
        trace("Main");
        btn_login.addEventListener(MouseEvent.CLICK, handleLoginClick);
        Facebook.init(APP_ID, handleInit);
      }

      private function handleInit(response:Object, fail:Object):void
      {
        trace("Main :: handleInit");
        if(response)
        {
          changeToLoginState();
        }
        else
        {
          trace("Main :: handleInit : Did not Init!")        
        }
      }

      private function handleLogin(response:Object, fail:Object):void
      {
        trace("Main :: handleLogin");
        if(response)
        {
          changeToLoginState();        
        }
        else
        {
          trace("Main :: handleLogin : Did not Log In!")
        }
      }

      private function handleLogout(success:Boolean):void 
      {
        trace("Main :: handleLogout");
        btn_login.label = 'Login';
        txt_status.text = "Logged Out";
      }

      private function handleLoginClick(evt:MouseEvent):void
      {
        trace("Main :: handleLoginClick");
        if(Facebook.getSession() == null || Facebook.getSession().accessToken == null)
        {
          trace("Main :: handleLoginClick : if");
          var fbLoginTimer:Timer = new Timer(1000, 1);
              fbLoginTimer.addEventListener(TimerEvent.TIMER_COMPLETE, doFBLoginTimerComplete);
              fbLoginTimer.start();
        } 
        else 
        {
          trace("Main :: handleLoginClick : else");
          Facebook.logout(handleLogout);
        }
      }

      private function changeToLoginState():void 
      {
        trace("Main :: changeToLoginState");
        btn_login.label = 'Logout';
        txt_status.text = "Logged In";
      }

      private function handleSessionChanged(success:Object, fail:Object):void 
      {
        trace("Main :: handleSessionChanged");
        changeToLoginState();
      }    

      private function doFBLoginTimerComplete(evt:TimerEvent):void
      {
        trace("Main :: doFBLoginTimerComplete");
        evt.target.stop();
        Facebook.login(handleLogin, {perms:"user_photos, publish_stream"});
        /*Facebook.callJS('redirect', {perms:"user_photos, publish_stream"});*/
      }
    }
  }

А вот HTML

    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <title>Page Title</title>
        <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
    </head>
      <body>
        <div id="FlashDiv">
          <h1>You need at least Flash Player 9.0 to view this page.</h1>
          <p>
            <a href="http://www.adobe.com/go/getflashplayer">
              <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
            </a>
          </p>
        </div>
        <script type="text/javascript">
          function redirect() 
          {
            alert("redirect");
           var params = window.location.toString().slice(window.location.toString().indexOf('?'));
           top.location = 'https://graph.facebook.com/oauth/authorize?client_id=&scope=email,publish_stream,offline_access,read_stream&redirect_uri=http://apps.facebook.com/someapp' + params;
          }

            $(document).ready(function(){
                swfobject.embedSWF("main.swf", "FlashDiv", "550", "400", "10");
            });
        </script>
      </body>
    </html>

На самом деле не уверен, в чем проблема.Любая помощь, будет здорово!Спасибо!

1 Ответ

4 голосов
/ 15 февраля 2011

По сути, вам нужно установить имя и идентификатор тега объекта, вы можете легко это сделать с помощью SWFObject, как вы можете видеть ниже.Вам также необходимо установить соответствующий атрибут allowcriptaccess.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
        <head>
            <title></title>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
            <script type="text/javascript">
                var flashvars = {};
                var params = {};
                params.allowscriptaccess = "sameDomain";
                var attributes = {};
                attributes.id = "FlashDiv";
                attributes.name = "FlashDiv";
                swfobject.embedSWF("main.swf", "FlashDiv", "550", "400", "10.0.0", "expressInstall.swf", flashvars, params, attributes);
            </script>
        </head>
        <body>
            <div id="FlashDiv">
                <a href="http://www.adobe.com/go/getflashplayer">
                    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                </a>
            </div>
        </body>
    </html>
...