title: How to access Actionscript from Javascript in Adobe AIR
body: <p>I have an AIR application written in html/javascript and I want to use the Actionscript print functions but I have no experience in Actionscript for AIR.</p>
  
  <p>Where do I put the Actionscript code ? Does it go into an mxml file or does it need to be compiled into a Flash application. Where do I put it and how do I include it into the html document ? Finally, how do I call the AS function from Javascript ?</p>
  
  <p><strong>=====update=====</strong></p>
  
  <p>I know I have to compile either an .mxml or .as file into .swf using mxmlc and I have the following in my .as file:</p>
  
  <pre><code>package {
      import mx.controls.Alert;
      public class HelloWorld {
          public function HelloWorld():void {
              trace("Hello, world!");
          }
      }
  }
  </code></pre>
  
  <p>Or alternately, this in a .mxml file:</p>
  
  
  
  <pre><code>&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"&gt;
      &lt;mx:Script&gt;
      &lt;![CDATA[
         import mx.controls.Alert;
  
             public function HelloWorld():void {
                 Alert.show("hello world!");
                 trace("Hello, world!");
             }
          ]]&gt;
      &lt;/mx:Script&gt;
  &lt;/mx:Application&gt;
  </code></pre>
  
  <p>This compiles OK, but when I include it in a html file with:</p>
  
  <pre><code>&lt;script src="actionscript.swf" type="application/x-shockwave-flash"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>I get the following error:</p>
  
  <p>TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at mx.managers::FocusManager/activate()
      at mx.managers::SystemManager/activateForm()
      at mx.managers::SystemManager/activate()
      at mx.core::Application/initManagers()
      at mx.core::Application/initialize()
      at actionscript/initialize()
      at mx.managers::SystemManager/<a href="http://www.adobe.com/2006/flex/mx/internal::childAdded()" rel="nofollow noreferrer">http://www.adobe.com/2006/flex/mx/internal::childAdded()</a>
      at mx.managers::SystemManager/initializeTopLevelWindow()
      at mx.managers::SystemManager/<a href="http://www.adobe.com/2006/flex/mx/internal::docFrameHandler()" rel="nofollow noreferrer">http://www.adobe.com/2006/flex/mx/internal::docFrameHandler()</a>
      at mx.managers::SystemManager/docFrameListener()</p>
  
  <p>Any ideas what that means ?</p>