Skip navigation
Currently Being Moderated

ExternalInterface always return null from IE

Jun 12, 2009 9:42 AM

I copied following code from the ExternalInterface example to my flash:

 

            if (checkJavaScriptReady()) {
                console.appendText("Javascript is ready.\n");
            } else {
                console.appendText("Waiting for javascript ...");
                var readyTimer:Timer=new Timer(500,0);
                readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
                readyTimer.start();
            }
function checkJavaScriptReady():Boolean {
    var isReady:Boolean=ExternalInterface.call("jsReady");
    return isReady;
}
function timerHandler(event:TimerEvent):void {
    var isReady:Boolean=checkJavaScriptReady();
    if (isReady) {
        console.appendText("\nJavaScript is ready.\n");
        Timer(event.target).stop();
    } else {
        console.appendText(".");
    }
}

in Firefox everthing works OK and half a second after a page loads I get "Javascript is ready." message. In Internet Explorer I get only dots appearing. Here is the JS code:

 <script type="text/javascript" language="JavaScript">
     var isReady = false;
     function jsReady() {
         return isReady;
     }
     function pageInit() {
         isReady = true;
        }
</script>
</head>
<body onload="pageInit();">

I try to debug the javascript in Internet Explorer and I trace it to function __flash__toXML inside DOM object for the movie, it checks the return type value and return a XML tag <true/> of <false/> depending on the value.

function __flash__toXML(value) {
   var type = typeof(value);
    if (type == "string") {
        return "<string>" + __flash__escapeXML(value) + "</string>";
    } else if (type == "undefined") {
        return "<undefined/>";
    } else if (type == "number") {
        return "<number>" + value + "</number>";
    } else if (value == null) {
        return "<null/>";
    } else if (type == "boolean") {
        return value ? "<true/>" : "<false/>";
    } else if (value instanceof Date) {
        return "<date>" + value.getTime() + "</date>";
   } else if (value instanceof Array) {
       return __flash__arrayToXML(value);
   } else if (type == "object") {
       return __flash__objectToXML(value);
   } else {
        return "<null/>"; //???
    }
}

When I debug an ExternalInterfaceExample just after the return statement it jumps to the code it executed before, but when I debug my application it goes to:

try { __flash__toXML(jsReady()) ; } catch (e) { "<undefined/>"; }

I also get a runtime error on unloading because it releses the ExternalInterface.callback that does not exist. Calling a callback defined with ExternalInterface.addCallback and the JS says that function is not defined (but it seems movie DOM javascript tries to free that function, I suppose it also trying to define it).

Any suggestions? What I am doing wrong? The ExternalInterfaceExample works ok, why my flash it doesn't?

 
Replies
  • kglad
    72,189 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 12, 2009 9:53 AM   in reply to IlluminatiBG

    try:

     

    IlluminatiBG wrote:

     

    I copied following code from the ExternalInterface example to my flash:

     

                if (checkJavaScriptReady()) {
                    console.appendText("Javascript is ready.\n");
                } else {
                    console.appendText("Waiting for javascript ...");
                   var readyTimer:Timer=new Timer(500,1);
                    readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
                    readyTimer.start();
                }
    function checkJavaScriptReady():Boolean {
        var isReady:Boolean=ExternalInterface.call("jsReady");
        return isReady;
    }
    function timerHandler(event:TimerEvent):void {
        var isReady:Boolean=checkJavaScriptReady();
        if (isReady) {
            console.appendText("\nJavaScript is ready.\n");
            Timer(event.target).stop();
        } else {
            console.appendText(".");
        }
    }

    in Firefox everthing works OK and half a second after a page loads I get "Javascript is ready." message. In Internet Explorer I get only dots appearing. Here is the JS code:

     <script type="text/javascript" language="JavaScript">
         var isReady = false;
         function jsReady() {
             return isReady;
         }
         function pageInit() {
             isReady = true;
            }
    </script>
    </head>
    <body onload="pageInit();">
    

    I try to debug the javascript in Internet Explorer and I trace it to function __flash__toXML inside DOM object for the movie, it checks the return type value and return a XML tag <true/> of <false/> depending on the value.

    function __flash__toXML(value) {
       var type = typeof(value);
        if (type == "string") {
            return "<string>" + __flash__escapeXML(value) + "</string>";
        } else if (type == "undefined") {
            return "<undefined/>";
        } else if (type == "number") {
            return "<number>" + value + "</number>";
        } else if (value == null) {
            return "<null/>";
        } else if (type == "boolean") {
            return value ? "<true/>" : "<false/>";
        } else if (value instanceof Date) {
            return "<date>" + value.getTime() + "</date>";
       } else if (value instanceof Array) {
           return __flash__arrayToXML(value);
       } else if (type == "object") {
           return __flash__objectToXML(value);
       } else {
            return "<null/>"; //???
        }
    }
    

    When I debug an ExternalInterfaceExample just after the return statement it jumps to the code it executed before, but when I debug my application it goes to:

    try { __flash__toXML(jsReady()) ; } catch (e) { "<undefined/>"; }
    

    I also get a runtime error on unloading because it releses the ExternalInterface.callback that does not exist. Calling a callback defined with ExternalInterface.addCallback and the JS says that function is not defined (but it seems movie DOM javascript tries to free that function, I suppose it also trying to define it).

    Any suggestions? What I am doing wrong? The ExternalInterfaceExample works ok, why my flash it doesn't?

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 29, 2009 8:13 AM   in reply to IlluminatiBG

    Which attribute was this?

    Thanks.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 5, 2010 9:26 AM   in reply to roidelapatate

    Make sure there's an "id" attribute on your <object> tag. The IE way of handling ExternalInterface.call(...) is to call a method on the <object>. IE issues the code

     

        document.getElementById("...").SetReturnValue(...)

     

    Without an id attribute on your object tag, this reduces to

     

     

        document.getElementById("").SetReturnValue(...)

     

    which tries to call SetReturnValue on a null object.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points