Why Native Extensions for AIR

Posted on September 6, 2011 | 25 comments

With the release of the RC builds of AIR 3.0 and Flash Player 11 on labs more details about the coming runtimes is being discussed publicly. I want to focus on one of the new features called Native Extensions for AIR, Oliver Goodman does a great job explaining the feature and some of the details of how it works. To get more information you will not want to miss MAX 2011 in LA.

Now to the why. Why would you use Native Extensions for AIR? Let us start at the beginning with content. Content and its requirements drive decisions about where you want to take your application. Does it require specific features that are not cross platform? Does it need to be multi-screen? Does it need to have a reasonable ROI on UI and business logic across multiple screen?

With the current release of AIR (2.7) a lot of high quality content can be built across screens (ie: CaltrainTimes), but with AIR 3.0 the possibilities grow even larger. Now when you need that one specialized feature across certain screens or all screens with AIR 3.0 you have the flexibility to look at Native Extensions as an option to extend AIR. My use case was creating an application for mobile devices that acts like a point of sale system, basically being able to take credit card transactions on the go. AIR is great for the use case to encapsulate my UI across the various platforms along with having all my business logic for the transaction with the merchant gateway. But what was lacking was the ability to interface with the various card reader device accessories.

To give my use case a try, I obtained a Magtek iDynamo credit card reader. The Magtek accessory fits into the bottom connector on a iPod or iPhone. I then created a XCode project and coded up the native Objective C code part of the Native Extensions for AIR. The Objective C code was the bare minimum of setting up the EAAccessory and waiting for an InputStream of data coming from the card reader. I created the ActionScript interface library to start up the EAAccessory and listen for data events. Even with being fairly new to Objective C and XCode library projects, I was still able to whip up an example from Objective C to ActionScript to Flex mobile application using Flash Builder 4.5.1 in less than a day. The result can be seen in the image below (my credit card # is masked and it is an expired/cancelled card):

I am sure there are a few questions around this new feature. For now, definitely read through Oliver’s article, come to MAX, and wait for the final runtime releases when more detail information and examples will be made available.

  • Anonymous

    “my credit card # is masked” … except it’s not. I hope it’s really expired and that your new card has a different number.

    • Anonymous

      Its masked per the PCI-DSS standards it is only showing the first 4 and last 4 digits, the ones in between are not valid numbers.

      • Anonymous

        Okay, phew. I’d call that “faked” though, simply because “masking” with zeros leads to people wasting their time trying, unnecessarily, to prevent you getting hurt. ;-)

        • Anonymous

          I see now that people are expecting some kind of special mask char like “#” over all the masked numbers. Thanks for the concern.

  • Jon Webb

    Renaun, your number is on the screen…

  • Michael Krotscheck

    Are external libraries linked? Say, if I wanted to use liblamemp3′s video encoding capabilities, am I going to have to GPL my code because it’s all compiled into one binary?

    Also, when (if ever) will this get pushed out to the Flash Player?

    • Anonymous

      From Oliver’s article:
      Android – Java Archive (.jar) or shared library (.so)
      iOS – Static library (.a)
      OS X – Framework (.framework)
      Windows – Dynamic Link Library (.dll)

      I can’t comment on licensing.

      This is for AIR not Flash Player, so not good answer on it coming to Flash Player.

      • Michael Krotscheck

        Yeah, I saw that. I’m more curious about how that list plays with these two statements:

        “Extensions contain both ActionScript and native code, and the boundary between the two can vary arbitrarily.”

        “…This is the kind of extension created by a typical ActionScript developer, whether for their own or shared use. It contains platform-specific implementations for multiple platforms, and each implementation is bundled with each application that uses it.”

        So the real question I guess is “Can we use GPL’d libs without having the lawyers from the FSF descend upon us?”, but YANAL, and I doubt Adobe will come out with an official statement on that (It’d be nice though).

        So barring that, the question is: “Is there documentation on exactly where that ‘arbitrary’ line falls so we can have our lawyers look it over and recommend whether we will incur the wrath of the FSF?”

        • Anonymous

          I don’t think that kind of detail will be available until release. As I understand it, it is an interface on the AS side and I use the specific ANE for each platform (where some are static and some are dynamic from the list posted in the last reply). Sorry not much help.

          • Michael Krotscheck

            No worries. I’ll keep my ears open at MAX to see what comes of it all :).

          • Jon Webb

            You’ll need to package liblamemp3 with your app, because it’s probably not preinstalled on the target device. That would be the defining factor.

  • James Ong

    I seen like HP, LGE, etc are using Flex on the frontend and .NET which control the UI and functionality. I believe Amethyst IDE was used by most companies. What are the difference between Amethyst and AIR 3 Native Extension? Which are the best bet?

    • Anonymous

      Are you talking about mobile applications or desktop?

  • James Ong


  • Pingback: Cool Stuff with the Flash Platform - 9/8/2011 | Remote Synthesis

  • Anonymous

    Yes but not recommended, but depends on your content.

  • Pingback: Adobe MAX 2011: A Year in the Making | Paul Trani

  • Pingback: Flash Player 11, AIR 3, and Flex/Flash Builder 4.6 | Ryan Stewart – Mountaineer Coding

  • Pingback: AIR Native Extension Example: iBattery for iOS | todd anderson

  • http://profiles.google.com/dadmyshitsays Sam Rivello

    WOW! This all sounds great. But how do we compare Flash-To-Mobile (AIR) vs Native (Objective-C) Development? And if we DO choose AIR, how do we decide to start with Flash or Flex?

    Here are two great articles!

    Great Article “Considering Flash-To-Mobile Development”

    Great Article “Flash-To-Mobile Dev: Flash vs. Flex”

  • cliper m

    In this blog you understand ANE

    I wrote a blog too

  • Master P

    I’m getting an error when trying to compile a native extension (.framework) for Mac OS X 10.7 with XCode 4.1; I’ve included “FlashRuntimeExtension.h” in the project but not sure if i’m missing something else as there is a lack of documentation for Native Extensions with XCode for a Mac Framework (the error I get is “_FRENewObjectFromBool” – symbol(s) not found for architecture i386

    • Anonymous

      I don’t know off the top of my head. Its busy with MAX right now so try the Adobe Forums or I’ll look it up when I get a chance.

  • Pingback: Why I’m Doing PhoneGap | Ryan Stewart – Mountaineer Coding

  • Pingback: What *IS* Wrong With AIR 3.0 Native Extensions!

  • Anonymous
  • http://www.liquid-photo.com Anthony

    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.

  • terrell cheaves

    Do you mind providing access to the credit card native extension you created?

    • Anonymous

      The code was basically the same EAAccessory sample code on Apple docs. I was just reading the bytes and pushing them up. I might put it up later.

  • http://twitter.com/sidneydekoning Sidney de Koning

    Hi Renaun,

    Were you able to actually pay or was this just a proof of concept to get the data from the reader?

    And any possiblility on sharing the source code for this poc? Love to see how you got this to work.


    • Anonymous

      This just gets the card info off the card. You would still have to implement all the specific merchant account side.