AIR apps from ActionScript
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);
}
}
}
Tags: ActionScript, Adobe, AIR, Window
jonah
April 21st, 2008 at 7:24 pm
Was looking for something about this. Thanks! Seem to have got it working. I’m having one problem though. It seems that I can only run the program once. It doesn’t exit gracefully. When I close the AIR window it seems to be still running, and I get an error the second time I try running the program. The only way I can get it to run again is to kill the process (ald.exe). Did you run into this problem? Any ideas why this might happen?
admin
April 22nd, 2008 at 8:34 pm
Are you using the Flex Builder for creating AIR apps? If so, when you start an app (you’ve clicked the little green bug), and you want to close it, you have to press the red stop button in the console pane.
I hope this solves your problem!
Ariza
October 24th, 2008 at 6:35 am
Good for people to know.