title: Trigger a flash objects function embedded via swfobject's embedSWF?
body: <p>I have looked through every resource I could find to create a streamlined way of doing this but I get one of the fundamental errors each time I try. I simply cannot get it to work!</p>
  
  <p>Here is my flash test actionscript from the first keyframe of my movie:</p>
  
  <pre><code>import flash.external.*; //THIS...
  
  System.security.allowDomain("http://localhost", "*"); //...AND THIS ALSO REQUIRED!
  
  if (ExternalInterface.available) {
      trace("ExternalInterface= " + ExternalInterface.available);
      flash.external.ExternalInterface.addCallback("myExternalMethod", null, myFunction);
  }
  
  function myFunction() {
      gotoAndStop(2);
  }
  </code></pre>
  
  <p>And here is my javascript/little bit of jQuery:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      var flashvars = {};
      var params = {
          wmode: "transparent", 
          allowscriptaccess: "always"
      };
  
      var attributes = { //The addition of these attributes make it work!
          id: "number-input",
          name: "number-input"
      };
  
      var embedHandler = function (e){
          mySWF = e.ref;
      };
  
      swfobject.embedSWF("images/flash-form.swf", "number-input", "800", "320", "9.0.0", "expressInstall.swf", flashvars, params, attributes, embedHandler);
  
      function executeFlash() {
          getObjectById("number-input").myExternalMethod(); 
      }
  
      function getObjectById(objectIdStr) {
          var r = null;
          var o = document.getElementById(objectIdStr);
          if (o &amp;&amp; o.nodeName == "OBJECT") {
              if (typeof o.SetVariable != undefined) {
                  r = o;
              } else {
                  var n = o.getElementsByTagName(OBJECT)[0];
                  if (n) {
                      r = n;
                  }
              }
          }
          return r;
      }
  
      $(function() {
          $('#main-button-big').click(function(event){
              event.preventDefault();
              executeFlash();
          });
  
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>The flash seems to embed successfully, if I do something silly like...</p>
  
  <pre><code>$(mySWF).hide();
  </code></pre>
  
  <p>...it hides, so I'm sure the script can see the object.</p>
  
  <p>No matter what methods I've tried to do I always (testing in firefox) get an error like:</p>
  
  <p>Error: TypeError: mySWF.myExternalMethod is not a function. </p>
  
  <p>In safari:</p>
  
  <p>TypeError: 'undefined' is not a function (evaluating 'mySWF.myExternalMethod()')</p>
  
  <p>If I try the jQuery version of getElementById (circumnavigating the embedHandler) I get:</p>
  
  <p>Error: TypeError: $(...).myExternalMethod is not a function. or TypeError: 'undefined' is not a function (evaluating '$('#number-plate-input').myExternalMethod()')</p>
  
  <p>I need to get this project finished rapidly and am at the end of my tether. Any help would be very gratefully received.</p>
  
  <p>UPDATED: Please note that the embedHandler is no longer needed, nor used to trigger any event of any kind. It is a useful piece of code though, so I've opted to leave it in.</p>