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?
Looking to get started using Native extension? Here’s a quick primer with links to more resources. What the heck are AIR Native Extensions?
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,
see http://www.rozengain.com/blog/2007/05/01/some-actionscript-30-optimizations.
To use a native extension in an AIR application, you have these three tasks to do:
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:
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.
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:
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.
Instead:
ExtensionContext.createExtensionContext() returns.getActivity() method.The Gyroscope and Vibration examples do exactly that. See them at http://www.adobe.com/devnet/air/native-extensions-for-air.html.
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.
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 http://www.adobe.com/devnet/air/native-extensions-for-air.html
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.
With the announcement of AIR 3 and its new native extension feature, detailed documentation about using Native Extensions for Adobe AIR is available now at:
Developing native extensions for Adobe AIR
You’ll find:
- Overview and conceptual information
- How to use the C and Java native extension APIs, plus reference pages
- How to package your native extension using ADT
- Details on the Extension Descriptor file
- Information on using Android shared libraries, and using resources on Android and iOS
If you are using a native extension in your AIR application, see:
Using native extensions in AIR applications
For lots of examples and tutorials, see this Adobe Developer Connection page:
http://www.adobe.com/devnet/air/native-extensions-for-air.htm
Todd Anderson just posted “iBattery”, a great example of a native extension for Adobe AIR on his blog.
His iBattery extension allows an AIR application to get the status of the battery of an iOS device — from ActionScript. Todd also gives a nice tutorial highlighting some of the details that go into creating a native extension.
You can see more examples of native extensions at the Adobe Developer Connection page http://www.adobe.com/devnet/air/native-extensions-for-air.html
Looking for some examples of native extensions for Adobe AIR?
Please see Native extensions for Adobe AIR on the Adobe Developer Connection.
This page lists three sample extensions developed by Adobe to help you learn how to create your own extensions. With native extensions, an AIR application developer, using ActionScript, can take advantage of platform-specific and device-specific native capabilities.
The examples include:
Obviously, “from ActionScript” is the key. The extension’s ActionScript code interfaces with the extension’s native code, so that the AIR app developer only has to use ActionScript.
The ADC page also includes a link to a great example by Sean Fujiwara. His example uses .NET to efficiently transcode BitmapData objects into .bmp, .jpg, and .png formats. We hope to add more examples from the community soon.
The Adobe AIR 3 Release Candidate is available, and includes this new feature: Native extensions for Adobe AIR.
Until now, native extensions were available on AIR for TV, but not for AIR on desktop or mobile devices. Now you can create an ActionScript library that can execute native code on all these devices. This means an AIR application developer, using ActionScript, can take advantage of platform-specific and device-specific native capabilities.
We’ll blog here about documentation and examples as they become available. In the meantime, you can read more about it in this Adobe Developer Connection article: Extending Adobe AIR.
And get the AIR 3 Release Candidate download to get started.
You can now develop AIR 2.5.1 for TV apps for Samsung Smart TVs.
Register at the Samsung D Forum to learn how to package AIR apps for Samsung Smart TVs.
Read this document: AIR for TV Application Guide for Samsung TVs. You will need to login to the Samsung D Forum to read the document, but you can quickly get a login id by following the instructions on the Samsung D Forum page.
You can learn more general information for developing AIR for TV apps at Developing AIR applications for television devices.
More information like samples, tutorials, and articles are at Flash Platform for TV.