ExternalInterface Does Not Work in IE
Copy link to clipboard
Copied
I have successfully used the ExternalInterface object to create hyperlinks with arguments that get passed to my swf file so that the appropriate page loads when clicking on a hyperlink with arguments appended to the URL (?page=x). Unless the browser is IE, in which case I get an error that the window[movieName] object is undefined. It doesn't seem to matter what I try. I would appreciate any insights. This code works fine in Chrome, Firefox, Safari, and Opera. It only fails in IE. The page is located on an aspx page that, as of this writing, can be found at http://www.bkbfightclub.com/photo_gallery.aspx.
Things I have tried:
Placing a button on the page to run the code after the page was completely loaded to see if it was a timing issue
Placing a procedure in the HTML after the flash object code to load the window[movieName] object to a variable
The HTML page code is as follows:
// In the <head> section
<script language="javascript" type="text/javascript">
function sendToJavaScript(val) {
// If there is a ? in the URL, find out what page value follows
if (location.search.replace('?', '') !== '') {
var params = getQueryParameters();
sendParamToFlash(params);
}
}
function getFlashMovie(movieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
// THIS LINE FAILS IN IE
return (isIE) ? window[movieName] : document[movieName];
}
function sendParamToFlash(page) {
//This function fails because the getFlashMovie() function returns "undefined"
getFlashMovie("gallery_pages").sendToActionscript(page);
}
function getQueryParameters() {
var query = window.location.href.split('?')[1];
//query won't be set if ? isn't in the URL
if (!query) {
return {};
}
else {
var param = query.split('=');
}
return param[1];
}
</script>
//******************************************
// ACTION SCRIPT
//******************************************
// Call to javascript, calling the JavaScript code only after the movie has loaded
// to be sure the object actually exists in the DOM.
this.addEventListener(Event.ENTER_FRAME, callJs);
function callJs(e:Event):void
{
{
removeEventListener(Event.ENTER_FRAME, callJs);
// The argument is for testing purposes only. It works, even in IE.
var result:Object = ExternalInterface.call("sendToJavaScript", "Event listener removed");
}
}
// I have placed this line inside the callJs() function to no avail. It still works in all browsers except IE.
ExternalInterface.addCallback("sendToActionscript", callFromJavaScript);
function callFromJavaScript(page):void
{
if(page>=0 && page<=3) //There are only four internal pages right now
{
// Calls AS code to change to the page passed from JavaScript
change_page(page);
}
}
//***************************
Copy link to clipboard
Copied
When embedding the swf (either using embed/object tags or swfobject), are you setting an "id" value on it? If not, that would be why it's not working.
Copy link to clipboard
Copied
Thank you for responding, but yes, I have properly set the ID. I don't think it would work in any browser without that.
