views:

1194

answers:

1

I am trying to call an action in a flash object from the javascript:

as:

function testExternalConnection(str:String):Void {
    _root.debug.htmlText = "testExternalConnection ok";
}
ExternalInterface.addCallback("testExternalConnection", this, testExternalConnection);

js:

var movie = getFlashMovie("ap1_mod_hidden")
movie.testExternalConnection();

with

function getFlashMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}

I'm including my flash using swfobject:

<span id="ap1_mod_hidden"></span>
<script type="text/javascript">
    // Setting up the flash player
    var flashvars = {
     mp3Path: "stop",
     artistName : "",
     trackName : ""
    };
    var params = {
     codebase: 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
     src: '/flash/ap1_mod.swf',
     quality: 'high',
     pluginspage: 'http://www.macromedia.com/go/getflashplayer',
     scale: 'showall',
     devicefont: 'false',
     bgcolor: '#999999',
     name: 'ap1_mod',
     menu: 'true',
     id: 'mod',
     allowFullScreen: 'false',
     allowScriptAccess:'always', //sameDomain
     movie: '/flash/ap1_mod.swf',
    wmode: "transparent",
    allowfullscreen: "true"
    };

    swfobject.embedSWF("/flash/ap1_mod.swf", "ap1_mod_hidden", "300", "300", "9.0.0", false, flashvars, params);
</script>

Nothing crazy here. So this code is working fine in everything but not in Internet Explorer (what a surprise :\ ). It is getting the movie object correctly but it is not able to call the externalinterface function. It's saying that the property is not defined.

I've looked on google and SO with no success... any help would be appreciated!

+2  A: 

I believe you want to use the id, not the div you're adding the swf too so:

function getFlashMovie(movieName) {
    return swfobject.getObjectById("mod");
}

since you're setting "mod" as the id.

quoo
swfobject.embedSWF does not actually insert the swf into the specified element, but instead replaces the element. Kind of weird!
Duncan Beevers
it is working, you can't imagine how helpful this was!
marcgg
glad to help! swfobject 2.0's new div replacing thing totally confused me the first time I tried to set up externalinterface too, the old version just replaced the innerHTML, so it was kinda unexpected.
quoo
yes, I was expecting it to change the innerHtml... Well thanks again :)
marcgg