Loading your ANE – order of operations

Opt In Image
Early bird offer on the ANE eBooks

 

Buy any Easy Native Extensions 2nd Edition package and get our $99 iOS + Android ANE Template completely free before the end of June 2015.

 

 

  • step-by-step guide to making your iOS extension in under an hour
  • library for data conversion between ActionScript and native code
  • tutorials
  • infographics
  • code included

A native extension that you app uses only gets loaded in memory if the app makes a call into it. We have so far covered a couple of steps that happen at that point: extension initialization and extension context initialization. Let us now look at the process of loading the ANE in terms of what order these calls are made in and which parts of the system make them. Below is a diagram that illustrates what happens when an iOS ANE is loaded in memory:

Initialization Sequence Diagram

1. The client app accesses the ANE

The app makes a call into the native extension library for the first time, typically by instantiating the class that provides the extension’s ActionScript API.

2. The AIR Library instantiates an ExtensionContext

The ActionScript part of the extension (the AIR library) requests an instance of flash.external.ExtensionContext from the Air Runtime by calling 

where:

extensionID is the same string identifier you defined in your extension descriptor;
extensionType is a string, which you can use to define different ‘types’ of your extension. This is not a type in

the programmatic sense, but rather a name that the ActionScript and the native side agree on. Based on what name is passed the extension can initialize its context in different ways, for example by exposing different sets of native functions and thus providing different behavior. You can pass NULL if your extension does not vary its behavior. 

3. AIR Runtime calls the Extension Initializer

The AIR Runtime, in turn, calls the extension initializer function, which you have implemented in native code. The extension initializer function name (C) or  class name (Java) is listed in your extension descriptor. The Extension Initializer provides AIR with information about the Extension Context Initializer.

4. The Extension Context is instantiated and initialized

Next, your ANE makes an Extension Context instance and now that AIR has information about the Extension Context Initializer, it makes a call into it. The main role of the Extension Context Initializer is to inform AIR about the native functionality that’s available for calling from ActionScript. Have a look at this article for details.

What else?

Important terminology:

Next, we’ll llook at the order of calls when an extension is unloaded.

Then we will get to the meat of an extension and discuss how function calls are made. There be pictures!

Over to you

At what stage is your ANE at the moment? What’s stopping you from finishing it? Let us know in the comments below.


Warning: count(): Parameter must be an array or an object that implements Countable in /home/easyna6/public_html/easynativeextensions_wp/wp-includes/class-wp-comment-query.php on line 399

Comments

  1. Finley

    Thank you for these guides; they are thorough, illustrative, and indescribably helpful.

    I am truly greatful for those like you, who see a necessity in a level of detail that elicits understanding.

    You achieve this tenfold! ^_^

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="">