Avatar Brit Gardner’s Site

all the code that’s fit to printf()

Actionscript 3 AIR Application

I’m toying with the idea of distributing the Space Survivor game as an AIR application rather than embedded in the space survivor site (or concurrently with). 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

  • 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:

  • Copy and past this, or write something similar in your main AS file:
  1. package
  2. {
  3.   import flash.display.NativeWindow;
  4.   import flash.display.NativeWindowInitOptions;
  5.   import flash.display.Shape;
  6.   import flash.display.Sprite;
  7.   import flash.display.StageScaleMode;
  8.  
  9.   public class SpaceSurvivor extends Sprite
  10.   {
  11.     public function SpaceSurvivor()
  12.     {
  13.       var options:NativeWindowInitOptions = new NativeWindowInitOptions();
  14.       var mainWindow:NativeWindow = new NativeWindow(options);
  15.       mainWindow.activate();
  16.       mainWindow.title = "Space Survivor v0.0.1";
  17.       mainWindow.width = 1024;
  18.       mainWindow.height = 768;
  19.       mainWindow.stage.scaleMode = StageScaleMode.NO_SCALE;
  20.       var shp:Shape = new Shape();
  21.       shp.graphics.beginFill(0×0000FF);
  22.       shp.graphics.drawRect(0,0,100,100);
  23.       shp.graphics.endFill();
  24.       mainWindow.stage.addChild(shp);
  25.     }
  26.   }
  27. }
  • Finally, hit the Run or Debug button and voila!  You’re good to go.

Also, look for more information here about petitioning Adobe to make a ‘Run as Desktop App’ an option for new Actionscript projects.

,

Passion Projects