最简单的Facebook - Flash实现不起作用

时间:2012-07-17 15:30:10

标签: facebook actionscript-3 flash facebook-actionscript-api

编辑:我正在尝试执行以下LOCALLY

我正在尝试为Flash应用程序执行一个非常简单的Facebook实现。我正在使用“GraphAPI_Web_1_8_1.swc”。以下是主要的时间轴代码:

import FBLog;
import fanlib.utils.Debug;

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

和FBLog类代码:

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));
        }
    }
}

由于某种原因,我不能调用 NEVER 中的'handleInit'功能。这是我在文本字段中得到的输出:

  

发布Facebook初始化...发布Facebook初始化......

我从来没有得到额外的“结束初始!”。

现在,我尝试将此SWF嵌入到看起来像这样的HTML中,但是 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>

相同的输出。我能做错什么?我正在使用的APP_ID是正确的。

1 个答案:

答案 0 :(得分:0)

这是一个非常烦人的问题,几乎“隐藏”在网络上(至少对我来说,很难找到答案)。

在您的HTML中使用嵌入部分:

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

当您在attributes对象中使用“name”属性时,FB JS可以在DOM树中找到您的影片并执行回调函数。 希望这能帮助你。

现在,我仍然遇到问题:这解决了Chrome,Firefox等问题。但是IE9没有。可能是因为JSON解析器存在问题。如果我找到答案,我会在这里发回一个链接。

干杯。