Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
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 /

Transferring data with AIR native extensions for iOS – Part 2: Exchanging Vector and Array objects between ActionScript 3 and C, C++, or Objective-C

by Tom Krcha

Tom Krcha
  • Adobe
  • flashrealtime.com

Content

  • Exchanging arrays between ActionScript 3 and C
  • Exchanging Vector objects between ActionScript 3 and C
  • Where to go from here

Created

9 July 2012

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
ActionScript Adobe AIR extensibility Flash Builder iOS Native extensions

Requirements

Prerequisite knowledge

To make the most of this article, you’ll need a good understanding of ActionScript, C, Flash Builder, Xcode, and using tools from the command line.


Additional required other products (third-party/labs/open source)

  • Xcode

User level

Intermediate

Required products

  • Flash Builder (Download trial)

Sample files

  • transferring-data-ane-ios-pt2.zip

In Part 1 of this series I showed how to exchange basic types such as Number, int, uint, String, and Boolean data between ActionScript 3 and C (or C++, C#, or Objective-C) for native extensions on iOS. In this article, I illustrate the same technique using arrays and Vector objects.

If you haven't done so already, I recommend reading Part 1 before proceeding with this article.

Exchanging arrays between ActionScript 3 and C

This example implements a native language reverseArray() function, which reverses the elements in an ActionScript Array object. For example, if it is provided [1,2,3] as an array it returns [3,2,1] .

Here is the ActionScript 3 code:

public function reverseArray(array:Array):Array{ var ret:Array= context.call("reverseArray",array) as Array; return ret; }

The C code is a bit more complex than the code for basic data types. It performs the following steps:

  • Get an array from the arguments
  • Find the array's length
  • Create a new ActionScript 3 Array instance in C
  • Loop through the original array and fill in the new array
  • Return the new array

Here is the code:

FREObject reverseArray(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]){ FREObject arr = argv[0]; // array uint32_t arr_len; // array length FREGetArrayLength(arr, &arr_len); FREObject populatedArray = NULL; // Create a new AS3 Array, pass 0 arguments to the constructor (and no arguments values = NULL) FRENewObject((const uint8_t*)"Array", 0, NULL, &populatedArray, nil); FRESetArrayLength(populatedArray, arr_len); NSLog(@"Going through the array: %d",arr_len); int32_t j = 0; for(int32_t i=arr_len-1; i>=0;i--){ // get an element at index FREObject element; FREGetArrayElementAt(arr, i, &element); // OPTIONAL: get an int value out of the element int32_t value; FREGetObjectAsInt32(element, &value); // log index and value NSLog(@"Get item %d: %d",i,value); NSLog(@"Set item %d: %d",j,value); FRESetArrayElementAt(populatedArray, j, element); j++; } return populatedArray; }

Exchanging Vector objects between ActionScript 3 and C

The implementation for exchanging Vector variables is almost identical to the implementation for Array variables. The key difference is in the creation of the Vector object. For a Vector with integer elements, that will look like this:

FRENewObject((const uint8_t*)"Vector.<int>", 0, NULL, &populatedArray, nil);

Here is the ActionScript 3 code for reverseVector , which implements the same functionality as reverseArray :

public function reverseVector(vector:Vector.<int>):Vector.<int>{ var ret:Vector.<int>= context.call("reverseVector",vector) as Vector.<int>; return ret; }

Here is the C code:

FREObject reverseVector(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]){ FREObject arr = argv[0]; // array uint32_t arr_len; // array length FREGetArrayLength(arr, &arr_len); FREObject populatedVector = NULL; // Create a new AS3 Vector, pass 0 arguments to the constructor (and no arguments values = NULL) FRENewObject((const uint8_t*)"Vector.<int>", 0, NULL, &populatedVector, nil); FRESetArrayLength(populatedVector, arr_len); NSLog(@"Going through the vector: %d",arr_len); int32_t j = 0; for(int32_t i=arr_len-1; i>=0;i--){ // get an element at index FREObject element; FREGetArrayElementAt(arr, i, &element); // OPTIONAL: get an int value out of the element int32_t value; FREGetObjectAsInt32(element, &value); // log index and value NSLog(@"Get item %d: %d",i,value); NSLog(@"Set item %d: %d",j,value); FRESetArrayElementAt(populatedVector, j, element); j++; } return populatedVector; }

Where to go from here

As I mentioned in Part 1, a good starting point for learning more about native extensions is the Native C API Reference for Adobe AIR extensions.

Part 3 of this series (to come soon) covers exchanging custom objects between ActionScript 3 and native extensions.

Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License+Adobe Commercial Rights

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

More Like This

  • Distributing AIR in the enterprise
  • Performance-tuning Adobe AIR applications
  • Tips for building AIR applications that can be easily updated
  • Adobe AIR and the experience brand
  • Deploying Adobe AIR applications seamlessly with badge install
  • Using the Adobe AIR update framework
  • Getting started with the custom install badge
  • Building Lupo: A case study in building commercial AIR applications
  • Using Badger for Adobe AIR applications
  • Developing cross-platform Adobe AIR applications

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