FREContextInitializer and FREContextFinalizer in C

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

So you already know that, in order to make calls from your AIR app into native code, you need an Extension Context. One of the Extension Context roles is to tell AIR what native functionality is available for calling from ActionScript and this happens during the Extension Context initialization. This post will show you how this is done in C – you can use that in your C, C++ or Objective-C code.


FREContextInitializer is an AIR C API function, which is called to initialize your Extension Context when it’s created. You provide an implementation for this function in your native code, following this signature:

extData – this parameter might look familiar. This is the same data that you set in your Extension Initializer function

ctxType – this is a string parameter, which lets you specify a context type. You set this as a String parameter in your ActionScript createExtensionContext call. In your FreContextInitializer implementation you have the option to set the context up differently, depending on the context type: you can expose one set of functions for one type and another set of functions – for another type.

ctx – the Extension Context you are initializing.

numFunctionsToSet – this tells AIR how many functions you will make available through the extension context.

functionsToSet – this is an array of FRENamedFunction objects, each of which tells AIR about a native function that you make available for calling from ActionScript.


In this example we ignore the context type and expose three native functions to be called from ActionScript.

as_startRecording” is how ActionScript will refer to the function when it needs to call it. &ASStartRecording is a pointer to the native implementation of the same function.


I bet you’ll be surprised to hear that FREContextFinalizer is called when your Extension Context is being disposed of. Were you?

The context finalizer is a function that you implement, following this signature:

where ctx is the context that’s being destroyed.


What else?

Next, we’ll have a look at the Java equivalent of the context initialization and finalization.

Then we’ll attempt to put some order in this bunch of initializers and see a graphic of how this happens and who calls who.

After that it will be the finalization’s turn: we’ll look at the order of calls when an extension is unloaded.

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


  1. bkuperberg

    great site and nice tutorials !

    I’ve been creating ANE for Windows for almost 2 years, and i’m currently trying to make my latest ANE working on MacOS too.
    I’ve been compiling the .framework in XCode 5 (on Mavericks), created the .ane, successfully compiled a test project, but the ane functions are not recognized (the famous error #3500 “The extension context does not have a method with the name […])
    I’ve searched everywhere, followed a lot of explanations but those articles are often too old (XCode 4, base SDK target OSX10.5..) and mainly explaining how to create iOS extensions.

    You seem to be up to date and not having any problems creating extensions for OSX today, what is your secret ? Would it be possible to create a small tutorial on how to configure XCode 5 for an OSX native Extension, and maybe an XCode template ?

    Thank you very much, i have at least 5 extensions i would like to put on your site, but i would like to make them cross platform before.

    • Radoslava

      Hi bkuperberg,

      I wonder whether you get the infamous error message when you debug, but not in a release build. If that’s the case, you’ve run into an AIR bug, which causes a confusion with where the files in the ANE package are on Mac OS.

      Thanks for the idea to do a tutorial on that – challenge accepted.

      In the mean time, see if this might provide some help. There is a great post on Adobe’s forums by sbaldizz:

      Let us know how it goes.

      • benkuper

        Thank you Radoslava,
        actually i managed to get an ANE compiling and working by starting off a new project from a working osx extension. I think this is due to some obscure settings in XCode making the exported functions inaccessible or invisible from AIR…
        I didn’t digg further because i have to work on the osx ANE now, but if i find the faulty setting i will post it there.

        Thank you very much

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