Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite 6
  • 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
  • Government

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

by Tom Krcha

Tom Krcha
  • Adobe
  • gamingnotes.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
ActionScriptFlash 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

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

  • 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 6
  • 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 (Updated) | Cookies

Ad Choices