2
votes

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.

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 ?

=====update=====

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:

package {
    import mx.controls.Alert;
    public class HelloWorld {
        public function HelloWorld():void {
            trace("Hello, world!");
        }
    }
}

Or alternately, this in a .mxml file:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
    <![CDATA[
       import mx.controls.Alert;

           public function HelloWorld():void {
               Alert.show("hello world!");
               trace("Hello, world!");
           }
        ]]>
    </mx:Script>
</mx:Application>

This compiles OK, but when I include it in a html file with:

<script src="actionscript.swf" type="application/x-shockwave-flash"></script>

I get the following error:

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/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.managers::SystemManager/initializeTopLevelWindow() at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::docFrameHandler() at mx.managers::SystemManager/docFrameListener()

Any ideas what that means ?

2

2 Answers

0
votes

You have to use air.trace where air is a predefined Javascript wrapper over utility AS packages.

I was assuming you were doing AIR development using HTML/AJAX.

However, otherwise, you need to use ExternalInterface to have the AS functions available to JS. Can you tell us why you need this?

0
votes

There's documentation on this found at: http://help.adobe.com/en_US/AIR/1.5/devappshtml/WS5b3ccc516d4fbf351e63e3d118666ade46-7ed9.html

Make sure you compile with acompc:

Note: To compile an ActionScript SWF library for use as part of an HTML page in AIR, use the acompc compiler

And also... since you're using the Alert class... it depends on the Flex Framework. Make sure when you compile the swf. You compile in the whole framework. (i.e. make sure -static-link-runtime-shared-libraries=true)