ExternalInterface always return null from IE
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?