Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Adobe AIR Developer Center /

Mac OS X Hello World native extension example

by Adobe

Adobe logo

Content

  • Contents of the ZIP file
  • The ActionScript library
  • The native library
  • Application usage
  • Where to go from here

Created

3 November 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Adobe AIR Flash Builder

Requirements

Prerequisite knowledge

Familiarity with building Adobe AIR applications for Mac OS X, including familiarity with C and Xcode.

 

Required third-party products

Xcode

  • Download

User level

Intermediate

Required products

  • Flex (Download trial)
  • Adobe AIR 3

Sample files

  • MacOS-NativeExtension-Test.zip

This example provides a simple native extension for Mac OS X systems. The extension provides the following functionality by using ActionScript code only or by calling native code from ActionScript code:

  • Returns a "Hello World" string.
  • Reverses the characters of a string.
  • Computes the nth prime number, and the time to compute it.
  • Inverts an array of numbers, and computes the time to do the inversion.
The example also includes an AIR application that uses the extension. The following figure shows the display of the application:
Figure 1. Display of an AIR application that uses this native extension
Figure 1. Display of an AIR application that uses this native extension

Contents of the ZIP file

The attached MacOS-NativeExtension-Test.zip file contains a file called instructions.txt that contains instructions for:

  • Installing the AIR runtime, the AIR 3 SDK, and the Flex 4.5.1 SDK.
  • Executing shell scripts that build the native extension and the AIR application that uses it.
It contains the following directories:

Directory name

Contents

00 - create cert

Shell script to create a certificate for signing the extension

01 - create swc

The source and shell script to build the ActionScript side of the extension

02 - create platform extension

Source, Xcode project, and shell script to build the native side of the extension

03 – create ane

Shell script to create the ANE file. Also, contains the extension.xml file.

04 – create dmg

Source and shell script to build the AIR application that uses the extension

05 – run on adl

Shell script to run the application using adl (AIR Debug Launcher)

The ActionScript library

The source code for the ActionScript library is in the following directory in the ZIP file:

NativeExtensions/01 - create swc/src/com/airrt/extensions

The ActionScript library contains two classes:

  • class Basic
  • class Advanced

The Basic class

The Basic class provides the public method helloWorld(). The parameter mode indicates whether to:

  • use the ActionScript code to provide the "Hello World" string
  • call a native function to provide the "Hello World" string
public function helloWorld(mode:uint = 0) : String { if ( mode == 0 ) { return "[Basic.as]: Hello World!"; } else { var ctx:ExtensionContext = ExtensionContext.createExtensionContext( "com.airrt.extensions", "Basic" ); return String( ctx.call( "helloWorld" ) ); } }

The Advanced class

The Advanced class provides the remaining functionality of the extension. Each of the following public methods takes a parameter mode that indicates whether to use only the ActionScript code, or to call the native code.

  • reverseString()
  • computeNthPrime()
  • timeLongOp() which inverts an array of numbers from 1 to n. The Advanced class constructor takes one parameter, which is the size of the array. This method returns a string showing the elapsed time for the operation.

The Advanced class also provides these public methods:

  • getElapsedTime() which computes the elapsed time for computing the nth prime number.
  • getUnsorted() which returns a string of the first few elements of the original array that timeLongOp() inverts.
  • getSorted() which returns a string of the first few elements of the inverted array.

Extension context types

This extension illustrates using two extension context types:

"Basic"
var ctx:ExtensionContext = ExtensionContext.createExtensionContext( "com.airrt.extensions", "Basic" );
"Advanced"
var ctx:ExtensionContext = ExtensionContext.createExtensionContext( "com.airrt.extensions", "Advanced" );

Each context type provides a different set of native functions. Multiple extension context types are useful when an extension provides more than one set of capabilities.

The native library

The Mac OS X native extension framework is implemented in C, using the native extension C API. The Xcode project and source file for creating the native side are in the following directory in the ZIP file:

NativeExtensions/02 - create platform extension/mac/TestNativeExtension

Some implementation details to note are:

  • The functions NativeExtensionsInitializer() and NativeExtensionsFinalizer() use the FREInitializer() and FREFinalizer() signatures.
  • The functions _ctxInitializer() and _ctxFinalizer() use the FREContextInitializer() and FREContextFinalizer() signatures.
  • The function _ctxInitializer() uses the ctxType parameter to determine which set of native functions to make available to the ActionScript side. It chooses between the "Basic" functions and the "Advanced" functions.
  • Native functions available to the ActionScript side use the FREFunction() signature . These functions are _Basic_helloWorld() , _Advanced_reverseString() , _Advanced_computeNthPrime() , and _Advanced_timeLongOp() .
  • The native function _Advanced_timeLongOp() illustrates manipulating an ActionScript Array instance from the native side. The native function receives the array as a parameter.

Application usage

A sample AIR application that uses the extension is in the following directory in the ZIP file:

NativeExtensions/04 - create dmg/src

To use the extension, an AIR application does the following:

  • Creates an instance of one of the extension classes: Basic or Advanced.
  • Calls methods of the created class instance.

For example, the following code calls the extension's helloWorld() method when the application user selects the appropriate button in the AIR application's display:

private function onHelloWorld() : void { var b:Basic = new Basic(); helloWorldResult.text = b.helloWorld(useASExtCode.selected ? 0 : 1); }

The following code calls the extension's reverseString() method when the application user selects the appropriate button:

private function onReverseString() : void { var a:Advanced = new Advanced(); reverseStringResult.text = a.reverseString(reverseStringSrc.text, useASExtCode.selected ? 0 : 1); }

Where to go from here

For more information about developing native extensions for Adobe AIR, see:

  • Extending Adobe AIR
  • Developing Native Extensions for Adobe AIR
  • Adobe native extension samples

For more information about using a native extension in an AIR application, see:

  • Using native extensions for Adobe AIR

Tutorials and samples

Tutorials

  • Using the iOS Simulator to test and debug AIR applications
  • Using the Amazon In-App Purchase Adobe AIR native extension for Android and Kindle Fire
  • Transferring data with AIR native extensions for iOS – Part 3
  • Exchanging Vector and Array objects between ActionScript 3 and C, C++, or Objective-C

Samples

  • Licensing Adobe AIR applications on Android
  • Using web fonts with Adobe AIR 2.5
  • Using Badger for Adobe AIR applications

AIR blogs

More
07/09/2012 Protected: Publishing Adobe AIR 3.0 for TV on Reference Devices
07/08/2012 Source Code: Adobe AIR 3.3 Retina Video Application
07/06/2012 Application specific File Storage on Adobe AIR based ios Application
07/04/2012 Recent Work - iPad/Android App: Inside My toyota

AIR Cookbooks

More
02/09/2012 Using Camera with a MediaContainer instead of VideoDisplay
01/20/2012 Skinnable Transform Tool
01/18/2012 Recording webcam video & audio in a flv file on local drive
12/12/2011 Date calculations using 'out-of-the-box' functions

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement