Windows ANE tutorial: The AIR library

At the end of this part you will have:

An AIR library, ready to be packaged in an AIR Native Extension for Windows.


10-15 minutes

Wait, have you done this first?

The first two parts of this tutorial walk you through building the native Windows library that your ANE will use. If you haven’t done that yet, you can do it after this part, but make sure you have a DLL built before you move on to packaging the ANE.

Step 1: Create a Flex Library Project

Note: You don’t need to read this step in detail if you already know how to set up a Flex Library.

In Flash Builder select File > New > Flex Library Project:

Create Flex Library Project

In the dialog that appears, tick Include Adobe AIR libraries. Name your project and save it. I have named mine DiaDrawWindowsANETutorialAIRLib:

Create a Flex Library Project

Leave the next step of the New Flex Library dialog set as default and click Finish to create your AIR library project.

Step 2: Create the AIR wrapper for your ANE

In this step you’ll add an ActionScript class to your AIR library, whose purpose will be to talk to Windows.

Add a new ActionScript class to the src/ folder of your project, name it WindowsExtensionWrapper, set its superclass to and put it in a package of your choice: mine is com.diadraw.extensions.

Why subclass EventDispatcher?

A lot of the work that happens in an Adobe AIR Native Extension is asynchronous. Getting asynchronous events from your Windows DLL is also one of the few ways that the code in the DLL can communicate with your AIR library. Making your extension wrapper inherit EventDispatcher allows you to pass these events back to an app that uses your ANE.

I won’t cover passing messages on Windows in this tutorial. Unless you scream loud and clear in the comments below, of course.

Do you remember the slightly lopsided way in which ActionScript and native code talk to one another? Click here for a quick reminder with cartoons.

Add a class to your ANE library


Flash Builder will automatically create this for you:

Step 3: Add the Extension Context

Let’s start adding functionality to your newly created class by having it create an extension context in its constructor. You will need the context instance to make calls to native code later on, so make it a private class member:

To instantiate an ExtensionContext you’ll need a unique string – an Extension ID. You will also need to listen to events that may come from your native code.

Below is the modified code for the WindowsExtensionWrapper class:

Step 4: Add the AIR API of your extension

As pompous as this sounds, that’s actually the meat of your AIR library: the functions that will serve as the interface between an app and the native code you wrote in the previous step of this tutorial.

Well, one function in this case. Add the following public method to your WindowsExtensionWrapper class:

Step 5: Add the extension descriptor

The extension descriptor tells AIR about the native library. Click here for a reminder of how that works.

Add a new XML file to your AIR library’s src folder and name it DiaDrawWindowsANETutorialAIRLib-extension.xml (you can give it any name, really).

Your project should now look like this:

Extension descriptor for Windows

And this is what your extension file should contain:

Build your project to make sure you don’t get any compiler errors and you are now ready to package your ANE.

What’s next?

Opt In Image
Early bird offer on the ANE eBooks


Buy any Easy Native Extensions 2nd Edition package and get our $99 iOS + Android ANE Template completely free before the end of June 2015.



  • step-by-step guide to making your iOS extension in under an hour
  • library for data conversion between ActionScript and native code
  • tutorials
  • infographics
  • code included

Warning: count(): Parameter must be an array or an object that implements Countable in /home/easyna6/public_html/easynativeextensions_wp/wp-includes/class-wp-comment-query.php on line 399

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">