title: AS3 function call from javascript
body: <p>I am trying to call a AS3 function from javascript but getting the following error in browser:</p>
  
  <p>Object doesnot support property or method myCreateFile .</p>
  
  <p>Below is the AS3 class:</p>
  
  <pre><code>package {
  import flash.display.Sprite;
      import flash.external.ExternalInterface;
      import flash.net.FileReference;             
  import flash.events.IOErrorEvent;
  import flash.events.Event;
  import flash.system.Security;
  
  public class CreateDoc extends Sprite {
      private static const DEFAULT_FILE_NAME:String = "example.txt";
  
      //FileReference Class well will use to save data
      private var fr:FileReference;
  
      public function CreateDoc()
      {
          // Register the function for external use.
          ExternalInterface.addCallback("myCreateFile", myCreateFile);
          Security.allowDomain("*");
      }
  
      public function myCreateFile():void
      {
          fr = new FileReference();
          //open a native save file dialog, using the default file name
          fr.save("Demo file", DEFAULT_FILE_NAME);
  
          fr = null;         
      }
  }
  }
  </code></pre>
  
  <p>HTML code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;      
      &lt;script type="text/javascript" src="swfobject.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          try{
              var flashvars = {};
              var params = {allowscriptaccess:"always", movie:"CreateDoc.swf", wmode:"opaque", menu:"false"};
              var attributes = {id:"flashcontent",  name:"flashcontent"};
              swfobject.embedSWF("CreateDoc.swf", "flashcontent", "800", "600", "10.0.0", "expressInstall.swf", flashvars, params, attributes);
          }
          catch(err){
              alert(err.message);
          }
      &lt;/script&gt;
  
      &lt;script type="text/javascript"&gt;
          function doFunction(){
              alert('Calling function..');
              try{
                  var myObj = document.getElementById("flashcontent");
                  myObj.myCreateFile();
              }
              catch(err){
                  alert(err.message);
              }
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id="flashcontent"&gt;
      &lt;/div&gt;
  
      &lt;input id="save file" type="button" value="clickme" onclick="doFunction();" /&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>Any idea what is wrong when I try to call the myCreateFile() AS3 function which is present in CreateDoc class from java script?</p>