Flash DailyNotes on ActionScript, Adobe AIR and Animate

Tech5 min read

What an AIR native extension actually does

AIR gives you a large set of built-in features, but some device capabilities are not exposed. A native extension (ANE) is a package that lets your ActionScript code call code written for the platform itself, such as Java or Kotlin on Android and Objective-C or Swift on iOS.

The three parts

  • The ActionScript library. A normal class API that your app imports. This is what you write against.
  • The native code. One implementation per platform, compiled and bundled into the package.
  • The descriptor. An XML file that declares which platforms the extension supports and where each implementation lives.

How calls travel

Your app creates an extension context and calls a method by name. The native side runs, then reports back either with a return value or by dispatching a status event. That means asynchronous work such as sensor readings comes back as events you listen for.

var ctx:ExtensionContext = ExtensionContext.createExtensionContext("com.example.sensor", "");
ctx.addEventListener(StatusEvent.STATUS, onStatus);
ctx.call("start");

function onStatus(e:StatusEvent):void {
    trace(e.code, e.level);
}

Using one in your app

  1. Add the extension package to your project's build path.
  2. List its identifier in the extensions section of your application descriptor.
  3. Package with the extension directory set, once per target platform.
  4. Test on real devices. The desktop simulator usually cannot run the native part.

More in Tech