Question

I am getting a 'swf is null' in the Firebug console when calling Facebook.login(handleLogin, {perms:"user_photos, publish_stream"}) using the Facebook Adobe Actionscript 3 1.5 Graph API. Not sure what the issue is, but here is the AS3 Code:

  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"});*/
      }
    }
  }

And here is the 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>

Really not sure what the issue is. Any help, would be great! Thanks!

Was it helpful?

Solution

Basically, you need to set the name and ID of the object tag, you can do that easily with SWFObject as you can see below. You also need to have the appropriate allowscriptaccess attribute set.

    <!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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top