Think Labs is an ongoing effort by Seven2 to provide research and educational opportunities in the web development and mobile field. To see what we’ve been cookin’ up, check out our blog postings.

Created by
Seven2 Login

Team Think Labs | Intro to Native Extensions
single,single-post,postid-2506,single-format-standard,ajax_fade,page_not_loaded,,,wpb-js-composer js-comp-ver-4.2.3,vc_responsive
Project Structure

Intro to Native Extensions



Adobe Air allows you to relatively quickly develop mobile applications for Apple iOS, BlackBerry Tablet OS and Google Android. There are some limitations on the type of device features you can program. To access hardware specific features like Networking, vibration controls and gyroscope feedback you will need to use Native Extensions. Native Extensions (NE) is a method of executing device specific native code through an Adobe Air project. The Native Extension code is complex and can handle a large variety of special cases but the packaged (swc file) NE code is simple to use in your Adobe Air project. For example, you can include one NE file in an Air project that controls vibration duration on the device. The Air project will make one call to tell the device to vibrate for X seconds and the NE code will handle weather the that feature exists on a specific device and if so can the vibration duration be set. This approach is called the Multiplatform Model where one NE is designed to communicate to several platforms.

NE can be custom built or you can use NE developed by others. When you incorporate a NE in your project, built by someone else, make sure you trust the source. NE run with full application privileges. There are several prebuilt NE available here are some examples:



Project Structure

1. Adobe Air App
2. Native Extension App
3. iOS Library Project
4. Android Library Project
5. …..



Sample Code

ExtensionContext API (Adobe Air) –>
<Adobe Air>

protected var _batteryExtension:Battery;
_batteryExtension = new Battery();
console.appendText( ( _batteryExtension.getBatteryLife() * 100 ).toString() + “%\n” );

<iOS Objective C>
// Access battery life.

FREObject GetBatteryLife(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {

UIDevice *device = [UIDevice currentDevice];
[device setBatteryMonitoringEnabled:YES];
float life = [device batteryLevel];

FREObject retVal;
FRENewObjectFromDouble( life, &retVal );
return retVal;

Native Extension to Adobe Air:

Native code can access ActionScript from via the FREObject type.
You can determine the type of object by using the FREGetObjectType or dynamically casting to a derived class.
For example, convert to an integer, floating point, Boolean, or string value.


-Update to the latest version of Flash Builder, and Air
-Converting to a P12 format combines your iOS developer/distribution certificate and the associated private key into a single file.