facebook登录的FlashContent的GetElementById为null

GetElementById is null for FlashContent for facebook login

本文关键字:null GetElementById FlashContent 登录 facebook      更新时间:2023-09-26

我尝试用js-sdk为flash facebook登录创建简单的ExternalInterface机制,但由于GetElementById("flashContent")为null,所以对flash的回调没有运行>>>控制台说。

我该怎么修?我已经在Firefox等中尝试过了,并给出了相同的结果。当我点击按钮时,它会调用checklogin-js,但当进程完成并尝试回调flash时,方法GetElementById(…).onLogin不会运行。

代码:

function requestLogin() {                
            FB.login(function(response) {
                if (response.authResponse) {
                    console.log('Welcome!  Fetching your information.... ');
                    FB.api('/me', function(response) {
                    console.log('Good to see you, ' + response.name + '.');
                });
                    document.getElementById('dua').onLogin();                        
                } else {
                    console.log('User cancelled login or did not fully authorize.');
                     document.getElementById('dua').onError();
                }
            });
        }
    </script>
    <div id="flashContent">
        <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" id="dua" align="middle">
            <param name="movie" value="dua.swf" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#ffffff" />
            <param name="play" value="true" />
            <param name="loop" value="true" />
            <param name="wmode" value="transparent" />
            <param name="scale" value="showall" />
            <param name="menu" value="true" />
            <param name="devicefont" value="false" />
            <param name="salign" value="" />
            <param name="allowScriptAccess" value="always" />
            <!--[if !IE]>-->
            <object id="dua" type="application/x-shockwave-flash" data="dua.swf" width="550" height="400">
                <param name="movie" value="dua.swf" />
                <param name="quality" value="high" />
                <param name="bgcolor" value="#ffffff" />
                <param name="play" value="true" />
                <param name="loop" value="true" />
                <param name="wmode" value="transparent" />
                <param name="scale" value="showall" />
                <param name="menu" value="true" />
                <param name="devicefont" value="false" />
                <param name="salign" value="" />
                <param name="allowScriptAccess" value="always" />
                <!--<![endif]-->
                <a href="http://www.adobe.com/go/getflash">
                    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                </a>
                <!--[if !IE]>-->
            </object>
            <!--<![endif]-->
        </object>
    </div>

AS3代码:

import flash.events.DataEvent;
import flash.events.MouseEvent;
flash.system.Security.allowDomain("*");
flash.system.Security.allowInsecureDomain("*");
tombol.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void{
FBconnect();
tombol.removeEventListener(MouseEvent.CLICK, onClick);
}
function FBconnect():void {
    teks.text = "masuk fbconnect";            
        ExternalInterface.call("requestLogin");
    ExternalInterface.addCallback("onLogin", onLogin);
        ExternalInterface.addCallback("onError", onError);
 }
function onError():void {
 teks.text = "onError";
     trace('error');
 }
function logout():void {
      ExternalInterface.call("FB.logout", null);
}
function onLogin():void {
 teks.text = "onlogin";
     trace("FB LOGIN");
     connectUser();
 }
 function connectUser():void {
     teks.text = "connectUser";
     ExternalInterface.addCallback("loadUser", userCallback);
     ExternalInterface.call("connectUser");
   }
 function userCallback(data:Array):void {
  teks.text = "user callback";
      trace("FB USER LOADED");
      var userData:Object = data[0];
  }

我已经找到了这个问题的解决方案。首先,当我尝试用flashContent设置id getelementbyid时,它运行不好。但当我尝试使用id="dua"时,它也没有运行。所以,我用inspect元素来检查它,发现显示的对象是第二个不包含id的对象。所以,我给出了一个id,并在getelementbyid中调用它。所以,当我尝试在任何浏览器中测试它时,它都能很好地运行,但当我试图在IE中测试时,我必须使用IE方法设置getelementbyid。

-CMIIW-