What is the Extension Context?

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

We have mentioned the Extension Context a few times already: 

I reckon it’s time to look at what actually an Extension Context is. Agreed?

It’s a middleman

You can think of the Extension Context as the middleman between ActionScript and Native code. It’s like a tour guide that speaks both languages and helps the two sides communicate with one another.

You can have one or more Extension Context instances in your native extension.

Extension Context on the ActionScript side

In ActionScript an Extension Context is an instance of flash.external.ExtensionContext. Its role is to allow your ActionScript code to do the following:

  • create one or more instances of the Extension Context: 
  • call native functions:

Here as_reverseArrayInPlace is the name of a function that is implemented in your native library and _array is an argument that this function takes. We will see how native functions are implemented and made available to ActionScript in a future post.

  • receive events sent from native code:

Extension Context on the native side

In your native code the Extension Context masquerades as an instance of FREContext. It’s the first thing that gets created when your extension is loaded and the Extension Initializer is called.

The C version of FREContext is defined as

In Java, unsurprisingly, FREContext is a class that you have to implement:

What’s next?

Next we will see how the Extension Context is created, initialized and destroyed.

Then we will have a look at an ActionScript example of handling the extension context.

Over to you

Which programming language do you use for the native code in your ANEs? 


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. David

    The ExtensionContext class is not available to me. The only thing available to me in the flash.external class is flash.external.ExternalInterface.

    I’ve tried with AIR24 as well as Flex 4.15.0 + AIR23. I’m using FlashDevelop and trying to build a library for an ANE, following your tutorial and your sample project I downloaded.

  2. David

    I was able to access ExtensionContext when building the project in FlashBuilder, as per your tutorial, so looks like it’s an Adobe imposed limitation.

Leave a Reply to David Cancel 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="">