AIR Native Extensions, ByteArray, and BitmapData

[Note: Updated on October 11, 2011 to note that multiple ByteArrays or BitmapDatas can be acquired at the same time in the AIR 3 implementation. —Oliver]

The new-to-AIR 3 native extensions capability includes not only a general-purpose API for manipulating ActionScript objects from native code, but also fast-path APIs that allow direct access to ByteArray and BitmapData objects.

Using these APIs, native code can get direct access to the memory that sits behind a ByteArray or BitmapData—no copies, no translations. In order to achieve that, native applications have to declare when they want access via an acquire call, and when they’re done via a release. In between the two, we restrict access to the rest of the API in order to guarantee the pointer that’s returned remains valid.

Furthermore, it’s possible to acquire two or more byte arrays or bitmaps at the same time so long as there no intervening calls to the rest of the API. This can be used, for example, to take image as an input for a filter and write directly to a second as the output.

As always, if you have ideas for enhancements to this and other features, you can vote for them at

See the Native Extensions documentation for more on working with ByteArray and working with BitmapData.

6 Responses to AIR Native Extensions, ByteArray, and BitmapData

  1. Drew says:

    Would this work for real-time Sound data? I was working on a guitar effects pedal app before, but had some serious performance issues…this might fix it?

    • Oliver Goldman says:

      Probably. Obviously I don’t know the details of your situation, but if you are limited here by ActionScript performance than dropping down to native code to implement the effects will give you a large potential performance gain.

  2. Carl Looper says:

    The native extension api (and the process api) is the best thing ever to happen to AIR. For a while there it looked like AIR was just going to sit there inside it’s own self imposed sandbox – for no reason at all. How on Earth was it ever going to compete with the other native app frameworks allowed to dance around it? It’s finally been allowed out of the sandbox and ready to join the party.

  3. cbigboy says:

    How to access android resource in java native extension….??
    I try to access android resource..
    for example, res/menu/menu.xml, res/values/strings.xml … etc…

    – –
    * This class was automatically generated by the
    * aapt tool from the resource data it found. It
    * should not be modified by hand.
    package com.flash.extension.nativelib;

    public final class R {
    public static final class attr {
    public static final class drawable {
    public static final int icon=0x7f020000;
    public static final int notification_icon=0x7f020001;
    public static final class layout {
    public static final int main=0x7f030000;
    public static final class string {
    public static final int extension_app_name=0x7f040001; -> “hi extension”
    public static final int extension_hello=0x7f040000;

    so i used getResourceId(“string.extension_app_name”) of FREContext API
    but it’s not work.. throw NotFoundException error..

    so i used context.getString(R.string.extension_app_name);
    it’s work, but return incorrect value.. -> return value is “0.0.0”..
    it’s versionName in xml of actionScript Client Project..

    why can’t access android resource in native extension??
    how to get android resource in java natvie extension..??

    Is it possible access resource in native extension??

    • Markus says:


      Where you able to get your getResourceId issue resolved? I’m having the same issue. I keep getting NotFoundException. I’m pretty sure I’m bundling my resources when I create the ANE.


  4. Anthony says:

    I have just release a blog post about creating a NativeAlert extension for AIR. It includes multiple buttons and dispatches ActionScript events when the user selects one of those buttons.
    the post can be found here.
    The source is on github and you can download the NativeAlert.ane file directly also

    Hope you guys like it.