Openfl access NativeApplication for AIR wrapped application

Hi! I’ve been developing an AIR application with OpenFL, publishing to swf and using adt to package the app.

I’ve been trying to close the app, but both Lib.fscommand("quit") and System.exit(0) do nothing. Usually I’d use NativeApplication.nativeApplication.exit(), but NativeApplication doesn’t seem to be available from OpenFL.

How can I do this?

Thanks.

@ibilon and @Gama11 have shown me this can be done with an extern. Create a flash->desktop folder and subfolder in your root path, and add the following file, NativeApplication.hx:

package flash.desktop;
import flash.events.Event;

extern class NativeApplication {
  public static var nativeApplication:NativeApplication;
  public function exit(errorCode:Int = 0):Void;
  public function addEventListener(type:String, listener:Event->Void, useCapture:Bool = false, priority:Int = 0, useWeakReference:Bool = false):Void;
}

This will allow you to call exit and add event listeners.

The idea of doing -air support in Lime tools again, has been floated around. Do you have an opinion about it? Should Lime support AIR?

If we did, we could (for example) handle this in lime.system.System for System.exit()

Flash has a lot of things going for it, but I’d rather have openfl’s Video and P2P working on native than having -air support (especially since you can just wrap a swf with adt and enable AIR stuff with <haxeflag name="air"/>)