views:

244

answers:

2

I have a flash movie that I need to get with javascript.

Here is how I embed it using swf object:

<div id="ap1_mod"></div>
<script type="text/javascript">
    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: '/public/flash/ap1_mod.swf',
     quality: 'high',
     pluginspage: 'http://www.macromedia.com/go/getflashplayer',
     scale: 'showall',
     devicefont: 'false',
     bgcolor: '#999999',
     name: 'ap1_mod',
     menu: 'true',
     allowFullScreen: 'false',
     allowScriptAccess:'always', //sameDomain
     movie: '/public/flash/ap1_mod.swf',
    wmode: "transparent",
    allowfullscreen: "true"
    };

    swfobject.embedSWF("/public/flash/ap1_mod.swf", "ap1_mod", "400", "50", "9.0.0", false, flashvars, params);
</script>

and here is how I try to access it:

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

As usual, it's working fine in Firefox and Safari, but it's breaking in IE. If I add an alert: to display what returns getFlashMovie I get "undefined".

Any idea?

Thanks a lot

+1  A: 

Could you specify an id in the params and then just use:

document.getElementById( 'theId' );

To reference the <object> that gets created by swfobject?

jimr
+2  A: 

According to the documentation, embedSWF replaces the element you specify with the object, so you'd just use:

var movie = document.getElementById("ap1_mod");

I haven't actually checked but because the div element is being replaced with an object element, it's possible it isn't re-registered as a property of window in IE.

Andy E
It fixed it! I didn't think of doing this. I'm always surprise by how this way to embed swf makes life easier. thanks
marcgg
No problem, glad that fixed it for you.
Andy E