Monday, October 3, 2011

AIR extensions in Java Part 4 -- using the extension

To use the extension, you reference the ANE file the same way you reference a SWC. Flash Builder 4.5.6 lets you include ANE files using the project dialog (there's a new category for ANEs). So if you have 4.5.6, you are set. If not, you'll have to do it manually.

Accessing the ANE in code
To the App code, your ANE looks just like  SWC. (In fact, during authoring, it is using the SWC that you packaged into the ANE.) So you just instantiate the classes or call static methods defined by the ActionScript side of the extension.

Note that the App code never uses the ExtensionContext class. That's for the ActionScript inside the extension only.

Here's a short example app that uses an ANE that defines the class com.example.DataExchange. As you can see, there's nothing special goin on (on the surface):

    import com.example.DataExchange;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    public class DataExchangeUser extends Sprite
        private var de:DataExchange = new DataExchange();
        public function DataExchangeUser()
            if( de != null )
                //Boolean test
                trace( "Boolean test pass? " + (de.negateBoolean( false ) && !de.negateBoolean( true )) );
             else trace("Null context");

Reference the extension in the application descriptor
The application descriptor of the app must reference the extension by ID within an <extensions> element:


Packaging the App
You package an app using an ANE in the same way as any other, with one crucial difference: you must use the -extdir flag to include the ANE file. (Just putting it in the app package like any other file won't work.)

Here's an example:

adt -package -target apk-debug
      -storetype pkcs12 -keystore /Users/cward/Documents/AndroidCert.p12 -storepass ####
      -extdir /Users/myacct/Documents/FlashProjects/AIRNativeExtensionPackage

Again, that last line is crucial, without the -extdir, your app package will include the ANE, but won't know what it is.


  1. Hi Azimuth,

    My motivation for publishing most of these posts on AIR extensions was because Adobe decided to release a beta version before our documentation was really even started. These are essentially my notes for writing said documentation. I had hoped to write and release a couple of complete, concrete examples, but Adobe decided that they didn't want their tech writers creating such examples (and soon afterwards decided they didn't require my particular services any more). So, I've moved on to other things and don't have anything else to share on the topic.

  2. This comment has been removed by the author.


Note: Only a member of this blog may post a comment.