New to AIR Native Extensions?

Looking to get started using Native extension? Here’s a quick primer with links to more resources. What the heck are AIR Native Extensions?

Optimizing network interaction in mobile applications

Optimizing Performance for the Flash Platform is filled with tips to make faster, more efficient Flash Player and AIR applications for desktop, mobile, and TV devices.

The chapter called Optimizing network interaction has some tips worth reviewing:

  • Use smart seeking.  Smart seeking improves performance when a user seeks to a new destination in a streaming video. Use Netstream.inBufferSeek.  (Adobe Flash Media Server 3.5.3 or greater required)
  • Divide your app into multiple SWF files. Multiple smaller SWF files means your content loads faster, especially on mobile devices with limited access to the network.
  • Provide event handlers and error messages for IO errors. Because network access can be less reliable on a mobile device, be sure to catch every IO error and keep the user informed.
  • Use Flash Remoting and AMF for optimized client-server data communication. As a binary format, Action Message Format (AMF) reduces the size of the data, improving the speed of transmission. Flash Remoting gateways, such as  ZendAMF, FluorineFX, WebORB, and BlazeDS, know how to handle the AMF format on behalf of the server side.
  • Cache assets locally after loading them. Avoid unnecessary loads from the network by saving files to the local file system, by using SharedObjects, or by saving data to a local database.

For more details on these tips, and other topics such as conserving memory and improving rendering performance, visit Optimizing Performance for the Flash Platform.

Jackie Levy, Content and Community Lead

Optimizing Flash and AIR applications for mobile

Looking for ways to build incredibly speedy Flash or AIR applications for mobile devices? If so, look no further than Optimizing Performance for the Flash Platform. Released last year, this guide is brimming with valuable tidbits, provided in part by Adobe’s own Thibault Imbert. It offers tips for optimizing performance on mobile devices, desktops and TVs, ranging from basic ActionScript best practices to sophisticated graphics rendering techniques.

Here are a couple of simple ActionScript optimizations from the Miscellaneous optimizations section of the ActionScript 3.0 performance chapter.

Avoid evaluating statements in loops
Another optimization can be achieved by not evaluating a statement inside a loop. The following code iterates over an array, but is not optimized because the array length is evaluated for each iteration:

for (var i:int = 0; i< myArray.length; i++)

It is better to store the value and reuse it:

var lng:int = myArray.length;
for (var i:int = 0; i< lng; i++)

Use reverse order for while loops
A while loop in reverse order is faster than a forward loop:

var i:int = myArray.length;
while (--i > -1)

These tips provide a few ways to optimize ActionScript, showing how a single line of code can affect performance and memory. Many other ActionScript optimizations are possible. For more information,

Configure Flash Builder 4.5 to use Flash Player 11 and AIR 3

I’ve seen several people ask how to set up Flash Builder 4.5 to develop applications that use Flash Player 11 and AIR 3 features. Here are the steps:

  1. Download playerglobal.swc from
  2. Copy it to [Flash Builder 4.5]/sdks/4.5.1/frameworks/libs/player/11.0.
  3. In Flash Builder > Project > Properties > Flex Compiler, set the minimum Flash Player version to 11.
  4. In the Flex Compiler properties, specify an additional compiler argument:

Graeme Bull of has created an (always) excellent video tutorial that walks you through the steps:

Setting Up Flash Builder 4.5 for Flash 11 and AIR 3 Apps


CPU optimization tips for the Adobe Flash Platform

Optimizing Performance for the Adobe Flash Platform contains a treasure trove of tips on less obvious performance enhancements. For example, chapter 3, “Minimizing CPU usage”, highlights the following CPU management features:

  • Pause and resume SWF files based on screen exposure: This is an automatic feature in Flash Player since version 10.1. Flash Player minimizes processing when SWF content goes off-screen.
  • Instance management: This feature introduced the hasPriority HTML parameter. By default, Flash Player doesn’t start SWF content that is not visible. You can override this behavior in most cases by using the hasPriority parameter.
  • Sleep mode: On mobile devices, Flash Player and AIR detect when the device backlight goes into sleep mode. When this event occurs, rendering of SWF content stops, and frame rates drop to 4fps. Because the frame rate stays above zero, all open data connections can remain open.
  • Freezing and unfreezing objects: You can use REMOVED_FROM_STAGE and ADDED_TO_STAGE events to keep objects that are no longer in the display list from consuming unnecessary CPU cycles.
  • Activate and deactivate events: By using events to detect when your application is activated or deactivated, you can reset the frame rate, freeze or unfreeze objects, or perform other CPU optimizations.
  • Mouse interactions: Detecting mouse interaction on many objects simultaneously can be CPU-intensive. You can reduce that overhead by disabling mouse interactions on objects that do not respond to mouse events.
  • Timers versus ENTER_FRAME events: To execute code at specific intervals you can choose between a timer or ENTER_FRAME events. The optimal choice for your situation depends on a number of factors, such as whether your application uses animation.
  • Tweening syndrome: Minimize the use of tweens, especially for content intended for low-performance mobile devices.

Visit the Optimization Guide to find out more about these topics and many others, including memory management, efficient use of the ActionScript language, rendering, networking, and database access.

Using Flash Builder 4.5.1 to compile an AIR App that uses a native extension

To use a native extension in an AIR application, you have these three tasks to do:

  1. Declare the extension in your application descriptor file.
  2. Include the ANE file in your application’s library path.
  3. Package the application.

This post is about Step 2 with regard to Flash Builder 4.5.1 projects.

Native extensions are packaged in ANE files. To compile an AIR application that uses a native extension, include the ANE file in the Flash Builder project’s build path.

In Flash Builder 4.5.1, do the following steps:

  1. Change the filename extension of the ANE file from .ane to .swc.
  2. Select Project > Properties on your Flash Builder project.
  3. Select the Flex Build Path in the Properties dialog box.
  4. In the Library Path tab, select Add SWC….
  5. Browse to the SWC file and select Open.
  6. Select OK in the Add SWC… dialog box. The ANE file now appears in the Library Path tab in the Properties dialog box.
  7. Expand the SWC file entry. Double-click Link Type to open the Library Path Item Options dialog box.
  8. In the Library Path Item Options dialog box, change the Link Type to External.

Now you can compile your application using, for example, Project > Build Project.

The part about changing the ANE file’s file extension from .ane to .swc is not strictly necessary. In step 4 above, when you browse to find the file, in the “Choose a SWC file” dialog box, you can change the setting of the Files Of Type drop-down field. It is set by default to *.swc.  Change it to *.*.

Now you can choose the ANE file. Then, continue with step 5 above.

However, when you build your Flash Builder 4.5.1 project with an ANE file rather than a SWC file, you get compiler warnings. The first warning is on the import statement for the extension class, saying that the extension could not be found. Successive warnings occur when you use the extension’s classes.

But interestingly, the application still builds and runs successfully.

Note: Adobe recommends using the next version of Flash Builder for developing native extensions for Adobe AIR. Sign up now to get access to the prerelease of Flash Builder 4.6.

For more information about using a native extension in your AIR application, see Using native extensions in AIR applications.

Detailed documentation about creating extensions is at Developing native extensions for Adobe AIR.

Starling example hints

Problems building and debugging the Starling example on Adobe Developer Connection? This blog posting might help.

Looking for ActionScript examples? Try this

There are tons of awesome code snippets and examples in the ActionScript Reference and ActionScript Developer guide. Learn about the enhancements we’re working to make it easier to find examples:

Native extensions: When to call FREContext instance methods

Here’s a little tidbit about developing native extensions for Adobe AIR for Android devices using the native extension Java API.

The main point: The call that your extension’s ActionScript side makes to ExtensionContext.createExtensionContext()  must return before the native side of the extension can call methods of the instance of your class that extends the  FREContext class.

Let’s break that down.

The AIR runtime instantiates your FREExtension instance the first time the  ActionScript side of your extension calls ExtensionContext.createExtensionContext().

The sequence of calls to your Java implementation of the FREExtension class is:

  • FREExtension implementation class constructor
  • initialize()
  • createContext()

In createContext(), you return an instance of your class that extends the FREContext class.

But be careful. The FREContext object can only be considered fully constructed once the ExtensionContext.createExtensionContext() ActionScript method has returned.

Therefore, do not call any methods of your FREContext instance until after the ExtensionContext.createExtensionContext() ActionScript method has returned.

For example, you might be tempted to call your FREContext instance’s getActivity() method in its constructor. Don’t do it. You’ll get an IllegalStateException if you do.


  • Provide an initialization method that the ActionScript side can call after ExtensionContext.createExtensionContext() returns.
  • In the initialization method, call your FREContext instance’s getActivity() method.

The Gyroscope and Vibration examples do exactly that. See them at

Detailed documentation about creating extensions is at Developing native extensions for Adobe AIR.

To use a native extension in your AIR application, see Using native extensions in AIR applications.

Pen tablet native extension example

Sean Fujiwara recently posted a native extension for Adobe AIR at AIR 3 Native Extension Example – PenTablet.

This extension lets an AIR application get the pressure sensitivity data from a Wacom Intuos 4 pen tablet on Windows 7.  It’s a good example of a Windows native extension that handles Windows messages and uses a native library — in this case, the pen tablet’s library.

Sean also provided another native extension for Windows that encodes a bitmap into BMP, JPEG, or PNG format using Microsoft .NET Framework 4.  See  AIR 3 Native Extension Example – ImageProcessor.

You can see more examples and tutorials of native extensions at the Adobe Developer Connection page

Detailed documentation about creating extensions is at Developing native extensions for Adobe AIR.

To use a native extension in your AIR application, see Using native extensions in AIR applications.