How ActionScript data is represented in C

Welcome to the first tutorial of the Translating between ActionScript and Objective-C series.

Before we get on with data conversion, we need to have a word about how the ActionScript types are represented in the AIR C API, which is what you use when you make iOS Native Extensions for AIR.

Most of the data you will be passing around will be either an argument of a function you call or a result of a function you call.


When you implement a function on the native side which you want to be callable from ActionScript by doing

your function needs to conform to the following signature:

You are already familiar with this signature from our post Communication between ActionScript and native code in an ANE. Click on the link if you need a reminder.

The interesting thing here is FREObject, which we see in a couple of places:

  • Arguments to the function arrive as an array of FREObject instances: this is whatFREObject argv[] signifies.
  • The function is expected to return a FREObject as a result.

If you open FlashRuntimeExtensions.h and look for the definition of FREObject, this is what you see:

What is void*?

This essentially means that FREObject is a void pointer. A pointer is a variable that holds a memory address. It can hold the memory address of something you expect to be of a particular type, for example:

Or it can hold a memory address of data which can be of any type and the type is not specified when the pointer is declared:

When you read the data located at the memory address which pointerToAnyType points to, you can interpret it as an int, as a string or as something else.

When you pass data from ActionScript to Objective-C, you can put pretty much anything in your list of arguments:

Both of these will arrive at the C side as FREObject, in other words as void *.

How does void* help with AIR data types?

The Adobe AIR C API gives you convenience functions that help convert a FREObject into the native type you expect. You can find a full list here.

To get the integer value out of the first argument, for example, you will need to do the following:

Getting an Objective-C NSString out of the second argument requires a little more work:

Dealing with image data pointed to by a FREObject involves even more elaborate checks and conversions.

You can see how the work stacks up. Instead of adding six lines of code every time you want to read a string argument, how about making it a one-liner:

This is what you are going to build over the next posts in this series: your own little library of one-liner helper functions that will be at your fingertips to save you time with any iOS ANE project.

Info: For a comprehensive data conversion guide and how to make it into a library download our eBook “iOS vs. ActionScript Data Types Guide”.

What’s next?

We start our conversion library with a few auxiliary functions.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">