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 3: Exchanging custom objects between ActionScript 3 and C, C++, or Objective-C

by Tom Krcha

Tom Krcha
  • Adobe
  • flashrealtime.com

Content

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

Created

16 July 2012

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
ActionScript 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

Xcode

  • Learn more

User level

Intermediate

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 Part 2, I showed how to use the same approach with arrays and Vector objects.  In this article, I extend the technique to custom objects.

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

Exchanging custom objects between ActionScript 3 and C

There are situations in which you want to transfer a custom object instead of a predefined object or a basic type. For example, you may want to exchange an array of positions in three dimensions. Position is, in this case, defined by an object with x, y, and z properties.

The first step is to initiate an Array instance. You can use the same approach outlined in Part 2: Exchanging Vector and Array objects between ActionScript 3 and C, C++, or Objective-C:

uint32_t arr_len = 10; // count of positions FREObject objectsPosition = NULL; FRENewObject((const uint8_t*)"Array", 0, NULL, &objectsPosition, NULL); FRESetArrayLength(objectsPosition, arr_len);

Next, define a custom Object, as you did with the Array in Part 2.  Here is an example from the getArrayOfPositions() function in the sample code:

// loop through array length and fill it with data for(uint32_t i=0;i<arr_len;i++){ FREObject position; // create an instance of Object and save it to FREObject position FRENewObject((const uint8*)"Object", 0, NULL, &position,NULL); // populate temporary vars x, y, z FREObject xPos; FREObject yPos; FREObject zPos; FRENewObjectFromInt32(10, &xPos); FRENewObjectFromInt32(20, &yPos); FRENewObjectFromDouble(30, &zPos); // fill properties of FREObject position FRESetObjectProperty(position, (const uint8*)"x", zPos, NULL); FRESetObjectProperty(position, (const uint8*)"y", yPos, NULL); FRESetObjectProperty(position, (const uint8*)"z", zPos, NULL); // add position to the array FRESetArrayElementAt(objectsPosition, i, position); }

The sample code for this article contains the following ActionScript functions:

public function getArrayOfPositions():Array{ return context.call("getArrayOfPositions"); }

Here is the associated C code:

FREObject getArrayOfPositions(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]){ uint32_t arr_len = 10; // count of positions FREObject objectsPosition = NULL; FRENewObject((const uint8_t*)"Array", 0, NULL, &objectsPosition, NULL); FRESetArrayLength(objectsPosition, arr_len); // loop through array length and fill it with data for(uint32_t i=0;i<arr_len;i++){ FREObject position; // create an instance of Object and save it to FREObject position FRENewObject((const uint8_t*)"Object", 0, NULL, &position,NULL); // populate temporary vars x, y, z FREObject xPos; FREObject yPos; FREObject zPos; FRENewObjectFromInt32(10, &xPos); FRENewObjectFromInt32(20, &yPos); FRENewObjectFromDouble(30, &zPos); // fill properties of FREObject position FRESetObjectProperty(position, (const uint8_t*)"x", zPos, NULL); FRESetObjectProperty(position, (const uint8_t*)"y", yPos, NULL); FRESetObjectProperty(position, (const uint8_t*)"z", zPos, NULL); // add position to the array FRESetArrayElementAt(objectsPosition, i, position); } return objectsPosition; }

The code above shows how to transfer instances of Object type.  You can also define your own type; for instance a Position type that includes x, y, and rotation properties.

The sample code also includes support for getting an individual instance of this Position type. The class is defined in Position.as:

package com.krcha { [RemoteClass(alias="com.krcha.Position")] public class Position { public var x:uint; public var y:uint; public var rotation:Number; } }

The ActionScript function is in IOSExtension.as:

public function getPosition():Position{ return context.call("getPosition") as Position; }

Here is the related C function from IOSExtension.m:

FREObject getPosition(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]){ uint32_t arr_len = 10; // count of positions FREObject position = NULL; FRENewObject((const uint8_t*)"com.krcha.Position", 0, NULL, &position, NULL); FRESetArrayLength(position, arr_len); FREObject xPos; FREObject yPos; FREObject rotation; FRENewObjectFromInt32(10, &xPos); FRENewObjectFromInt32(20, &yPos); FRENewObjectFromDouble(1.57f, &rotation); FRESetObjectProperty(position, (const uint8_t*)"x", xPos, NULL); FRESetObjectProperty(position, (const uint8_t*)"y", yPos, NULL); FRESetObjectProperty(position, (const uint8_t*)"rotation", rotation, NULL); return position; }

Where to go from here

To learn more about native extensions check out the Native C API Reference for Adobe AIR extensions.

Also be sure to visit Native extensions for Adobe AIR in the Adobe AIR developer center.

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