質問

EDIT : I am trying to do the below LOCALLY

I am trying to do a very simple Facebook implementation for a Flash application. I am using "GraphAPI_Web_1_8_1.swc". Here is the main Timeline's code :

import FBLog;
import fanlib.utils.Debug;

addChild(Debug.field); // simply adds a textfield on stage for debugging
FBLog.INSTANCE;

and FBLog Class code:

package {

    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.events.MouseEvent;
    import fanlib.utils.Utils;
    import fanlib.utils.Debug;
    import com.facebook.graph.Facebook;

    public class FBLog extends EventDispatcher
    {
        static public const CONNECTED:String = "CONNECTED";
        static public const INSTANCE:FBLog = new FBLog();

        private var _applicationID:String;
        private var _extendedPermissions:Object;

        public function get applicationID():String { return _applicationID; }

        public function FBLog() 
        {
            super();
            if (INSTANCE) throw "What?";

            new DelayedCall(init, 0.5);
        }
        private function init():void {
            _applicationID = "408526019168127";

            //Set permissions to ask for
            _extendedPermissions = {scope:"read_stream, publish_stream, user_about_me, read_friendlists, user_photos"};

            //Initialize facebook
            try {
                Debug.field.appendText("Issuing Facebook init...");
                Facebook.init(_applicationID, handleInit);
                Debug.field.appendText("Issued Facebook init...");
            } catch (e:Error) { Debug.field.appendText("Facebook not initialized!" + "\n" + e); }
        }
        private function handleInit(response:Object, fail:Object):void {
            Debug.field.appendText("end init!");
            if (!response) response = {};
            if (!fail) fail = {};
            trace(Utils.PrettyString(response), Utils.PrettyString(fail));
            dispatchEvent(new Event(CONNECTED));
        }

        public function login(e:MouseEvent = null):void {
            Debug.field.appendText("start login");
            Facebook.login(handleLogin, _extendedPermissions);
        }
        private function handleLogin(response:Object, fail:Object):void {
            Debug.field.appendText("end login");
            if (!response) response = {};
            if (!fail) fail = {};
            Debug.field.appendText(Utils.PrettyString(response) + "\n" + Utils.PrettyString(fail));
            dispatchEvent(new Event(CONNECTED));
        }
    }
}

For some reason that is beyond me, the 'handleInit' function in NEVER called. Here is the output that I get in the textfield:

Issuing Facebook init...Issued Facebook init...

I never get the additional "end init!".

Now, I tried to embed this SWF in an HTML that looks like this, but TO NO AVAIL :

<!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>Digital TradeShow</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <style type="text/css" media="screen">
            #myContent              { width:1300 height:700; }
            body                    { margin:0; padding:0; overflow:auto; text-align:center; background:white;}
            #myAlternativeContent   { /* style alt content */ }
        </style>
        <script type="text/javascript" src="swfobject.js"></script>
        <script type="text/javascript">
            var flashvars = {};
            var params = { allowfullscreen:"true", wmode:"window" };
            var attributes = {};
            swfobject.embedSWF("FBLog.swf", "myContent", "1300", "700", "10.2", "expressInstall.swf", flashvars, params, attributes);
        </script>
        <script type="text/javascript">
            function PopupCenter(pageURL,title,w,h,scroll) {
                var left = (screen.width/2)-(w/2);
                var top = (screen.height/2)-(h/2);
                var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars='+scroll+', resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
                } 
        </script> 
        <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
    </head>
    <body>
        <div id="fb-root"></div>
        <div id="myContent">
            <div id="myAlternativeContent">
                <h1>Alternative content</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>
        </div>
    </body>
</html>

Same output. What could I be doing wrong? The APP_ID I am using is correct.

役に立ちましたか?

解決

This is a very annoying problem and almost "hidden" in the web (at least for me it was very difficult to find the answer).

In your HTML use this on embed section:

var attributes = {
    name:"myContent",
    id:"myContent"
};

When you use the "name" property in the attributes object, the FB JS can find your movie in the DOM tree and execute the callback function. Hope this help you.

Now, I still having a problem: this solves the problem with Chrome, Firefox, etc. But with IE9 no. Probably because a issue with the JSON parser. If i find the answer, i will back and post a link here.

Cheers.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top