Wednesday, June 24, 2009

Pure Actionscript AIR Project in Flex Builder

Sometimes you want to create a small application and not bother with all flex/mxml stuff. Either it’s pure ActionScript, or it uses other framework than flex (yes, such thing exists!, for example ASwing or just V3 Components from CS3/CS4), you might want to set up an AIR project that starts from a simeple .as file.

Currently, there is no obvious option in the Flex Builder interface. But, as a matter of fact, it is quite simple. Create a FlexProject, select AIR - Desktop Application in the first screen and change Main application file from .mxml to .as

Then, add some code in the constructor of your main class:

public function ProjectName()
{
var win:NativeWindow =
new NativeWindow(new NativeWindowInitOptions());
win.activate();
win.addEventListener(Event.CLOSE, function():void {
NativeApplication.nativeApplication.exit(0);
});

win.stage.addChild(this);

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

graphics.lineStyle(1, 0, 1);
graphics.drawCircle(100, 100, 80);
}

If you already have a web application and want to create an AIR version of it, extend the main class with one that only adds the AIR hooks.

No comments:

Post a Comment