Creating an Actionscript3-Only AIR Project

From As3gaming

Jump to: navigation, search

Took me a while to find information about how to build an AIR app from just AS3 source, so I thought I'd share. Requires Flex Builder 3:

  • Create a new Flex Project and specify that it is a Desktop application

Image:desktopopt.png

  • Follow your normal project-creation procedure
  • After the project is created, Make a new Actionscript file - name it whatever you want. Make sure your Class extends Sprite or MovieClip.
  • Right click the newly created .as file and mark it as your default application:

Image:defaultopt.png

  • Copy and past this, or write something similar in your main AS file:
package
{
	import flash.display.NativeWindow;
	import flash.display.NativeWindowInitOptions;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.StageScaleMode;

	public class SpaceSurvivor extends Sprite
	{
		public function SpaceSurvivor()
		{
			var options:NativeWindowInitOptions = new NativeWindowInitOptions();
			var mainWindow:NativeWindow = new NativeWindow(options);
			mainWindow.activate();
			mainWindow.title = "Space Survivor v0.0.1";
			mainWindow.width = 1024;
			mainWindow.height = 768;
			mainWindow.stage.scaleMode = StageScaleMode.NO_SCALE;
			var shp:Shape = new Shape();
			shp.graphics.beginFill(0x0000FF);
			shp.graphics.drawRect(0,0,100,100);
			shp.graphics.endFill();
			mainWindow.stage.addChild(shp);
		}
	}
}
  • Finally, hit the Run or Debug button and voila! You're good to go.

Also, look for more information on the Adobe Issue Tracker about petitioning Adobe to make a 'Run as Desktop App' an option for new Actionscript projects.

Personal tools