AIR apps from ActionScript
Saturday, April 19th, 2008This morning, I’ve lost some hours searching for a way to create an AIR app straight from ActionScript with Adobe FlexBuilder 3.
When you create a new Flex app, you can chose between a normal Flex app and an AIR app. With a new ActionScript project, you can’t.
You can create an AIR app from a standard .swf, but then you can’t use the native AIR framework.
Now, here’s a solution:
You create a new Flex project with AIR export in the Flex Builder.
In your favorite text-editor (e.g. TextWrangler) you open hidden .actionScriptProperties file, located in the root of your project folder.
You change the <application path=”<sourcefile>.mxml”/> into <application path=”<sourcefile>.as”/>. Make sure you have created the .as file
Now create a new NativeWindow in the constructor of the ActionScript class and …
now build your app.
You’ve just created an AIR app, based on an ActionScript class.
Source:
/**
* import required classes
*/
import flash.display.NativeWindow;
import flash.display.NativeWindowInitOptions;
import mx.controls.Label;
public class myApp {
public function myApp() {
// set the window properties first
var myWinProps:NativeWindowInitOptions = new NativeWindowInitOptions();
// now create a new window, with the predefined window properties
var myWin:NativeWindow = new NativeWindow(myWinProps);
// make the window appear
myWin.activate();
// create a new label
var helloWorldLbl:Label = new Label();
// add text to the label
helloWorldLbl.text = “Hello World”;
// now add it to the stage of the new window
myWin.stage.addChild(helloWorldLbl);
}
}
}