My post on creating native alerts with Adobe AIR has proven to be quite popuplar so I decided to follow it up with something even better (at least for Windows apps).

Recently I have been dabbling in a bit of C# for creating Windows Store apps as well as some C/C++ to try and figure out how to create Native Extensions (ANE) for Adobe AIR. As a first ANE I decided to make a native dialog extension. Extensions for this already exist for iOS and Android but I was unable to find any for Windows.

For anyone wanting to make an ANE for windows I recommend this tutorial which runs through everything from setting up a Visual Studio project to compiling the .ANE file. I found it very useful. So here is my first ANE. You can download the compiled the ANE below or the source files with the Visual Studio project and AS files. Read on for more details.

[Download ANE]
[Download source]

ane1

It should be pretty straight forward to use. First you need to include the ANE in your project. In Flash Professional you can go to ActionScript settings, click on the Library Path tab then click the Browse to Native Extension button.

Once it’s included you can use it as follows:

import com.nemenvisual.NativeDialog;

var ane:NativeDialog = new NativeDialog();
// displays a simple alert with an OK button
ane.alert("Alert title","This is an alert dialog.");

As you can see an advantage of using this ANE over my other solution using the HTMLLoader is that you can specify a title for the message box.

You can also use the customDialog method to specify the buttons you want to use and the icon to be displayed in the box.

// displays a dialog with Cancel, Try Again and Continue buttons and an exclamation icon.
var result = ane.customDialog("Custom alert", "The message in the custom alert.", NativeDialog.CANCELTRYCONTINUE, NativeDialog.ICONEXCLAMATION);

if (result == NativeDialog.IDRETRY)
{
  // the retry button was clicked
}

// or

switch (result)
{
  case NativeDialog.IDCANCEL:
    // cancel was clicked
    break;
  case NativeDialog.IDRETRY:
    // retry was clicked
    break;
  case NativeDialog.IDCONTINUE:
    // continue was clicked
    break;
}

Methods

There a five types of dialogs you can show. Currently there is no ‘prompt’ equivalent for user input.

Constants

The NativeDialog ANE implements most of the constants specified on the MSDN MessageBox page except where there are duplicates (for example MB_ICONEXCLAMATION and MB_ICONWARNING will show the same icon). I will add a modality option in the future to enable non-blocking dialogs.

Icon constants:

Button constants

Button IDs (returned by customDialog)

[Download ANE]
[Download source]