Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
Locked
0

ExternalInterface Does Not Work in IE

Community Beginner ,
Jul 29, 2009 Jul 29, 2009

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

1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 31, 2009 Jul 31, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 31, 2009 Jul 31, 2009
LATEST

Thank you for responding, but yes, I have properly set the ID.  I don't think it would work in any browser without that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines