Search code examples
javascripthtmlflashexternalinterface

Elegant way to get ExternalInterface working with all browsers


I want to call a function inside a Flash movie from javascript, using the ExternalInterface class. The problem is that to get it to work with Firefox I need to use the embed element and with the rest I have to get the object element. To solve it, I gave different ids to that two elements and depending on the user agent I select one or the other:

 function getMovie(movieName) {

    alert(navigator.userAgent);
     if (navigator.userAgent.indexOf("Firefox") != -1) {
         return document["flash_embed"];
     } else {
         return document["flash_object"];
     }
 }

This works, but it is not very elegant and it may not work with other browsers... Do you know a better way to do this?


Solution

  • Use swfobject to embed your flash movie, and then use it to retrieve the correct id.