title: Javascript call AS3 function
body: <p>I know that there are lots of articles and forum post about this question and lots of them are not working and remained unanswered. Some tutorials claimed that their code works, but some of them does not have download page and some of them with download page, the link does not work. Also, perhaps there's a new way of doing this and the code that I found is no longer supported. </p>
  
  <p>Here is my code:HTML and Javascript</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;&lt;title&gt;Javascript to SWF&lt;/title&gt;
  &lt;script language="JavaScript"&gt; 
  function getFlashMovie(movieName) {
      var isIE = navigator.appName.indexOf("Microsoft") != -1;
      return (isIE) ? window[movieName] : document[movieName];
  }
  
  function callToActionscript() 
  {
       getFlashMovie("jscallswf").setMouseXY();
  }
  
  callToActionscript();
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body style="background:red;"&gt;  
  &lt;body&gt;
      &lt;object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="450" id="jscallswf" align="middle" data="jscallswf.swf" style="height: 250"&gt;
          &lt;param name="allowScriptAccess" value="sameDomain"&gt;
          &lt;param name="allowFullScreen" value="false"&gt;
          &lt;param name="movie" value="jscallswf.swf"&gt;
          &lt;param name="quality" value="High"&gt;&lt;param name="bgcolor" value="#ffffff"&gt;
          &lt;embed src="jscallswf.swf" quality="High" bgcolor="#ffffff" width="400"     name="jscallswf" align="middle" allowscriptaccess="sameDomain" allowfullscreen="false"     type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer"     style="height: 250"&gt;
      &lt;/object&gt;
  &lt;/body&gt;
  &lt;/body&gt; 
  &lt;/html&gt;
  </code></pre>
  
  <p>AS3 code: </p>
  
  <pre><code>import flash.external.ExternalInterface;
  
  ExternalInterface.addCallback("setMouseXY", rotateCam);
  function rotateCam()
  {
      td.text = "NEWTEXT";
  }
  </code></pre>
  
  <p>Here is another Javascript approach: </p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;&lt;title&gt;Javascript to SWF&lt;/title&gt;
  &lt;style type="text/css"&gt;
  #jscallswf {
  margin:300px;
  }
  &lt;/style&gt;
  &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"&gt;    &lt;/script&gt;
  &lt;script type="text/javascript" src="swfobject.js"&gt;&lt;/script&gt;
  &lt;script language="JavaScript"&gt; 
  // JS Code
  // Embedding through SWFObject rocks in comparison with Adobe's garbage:
  
  var flashvars = {};
  
  var params                  =   {};
  params.menu                 =   "false";
  params.salign               =   "t";
  params.scale                =   "noscale";
  params.wmode                =   "transparent";
  params.allowScriptAccess    =   "always";
  
  var attributes              =   {};
  attributes.id = "jscallswf";
  
  swfobject.embedSWF("jscallswf.swf", "flashDiv", "274", "246", "9.0.0", "", flashvars, params, attributes);
  
  // Functions needed for calling Flex ExternalInterface
  function thisMovie(movieName) 
  {
      if (navigator.appName.indexOf("Microsoft") != -1) 
      {
          return window[movieName];
      } 
      else 
      {
          return document[movieName];
      }
  }
  
  function callFlashMethod()
  {
      thisMovie("jscallswf").setMouseXY();
  }
  
  
  $(document).ready(function(){
      callFlashMethod();
  });
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body style="background:red;"&gt;  
  &lt;body&gt;
  &lt;div id="flashDiv" style="margin:200px;"&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/body&gt; 
  &lt;/html&gt;
  </code></pre>
  
  <p>Both returning error in console "Uncaught TypeError: Cannot call method 'setMouseXY' of undefined"</p>