Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy 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
Promotions
Estimated shipping
Tax
Calculated at checkout
Total
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
  • gamingnotes.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
ActionScriptAdobe AIRextensibilityFlash Buildergame developmentgamingiOSmobilenative extensions
Was this helpful?
Yes   No

By clicking Submit, you accept the Adobe Terms of Use.

 
Thanks for your feedback.

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

  • Developing cross-platform Adobe AIR applications
  • Performance-tuning Adobe AIR applications
  • Using Badger for Adobe AIR applications
  • Building a native extension for iOS and Android – Part 2: Developing the ActionScript library
  • Creating your first Adobe AIR application on Android
  • Using web fonts with Adobe AIR 2.5
  • Signing Adobe AIR applications
  • Using push notifications in AIR iOS apps
  • Building Lupo: A case study in building commercial AIR applications
  • Using the Push Notifications native extension for iOS

Products

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

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 © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

Ad Choices

Reviewed by TRUSTe: site privacy statement