views:

309

answers:

2

I'm writing an Air application using only Actionscript, and Flex3 SDK as the compiler. Everything compiles and runs fine under adl, but when the final air file is built and installed, the main class is never initialized. For instance:

package {
    import flash.display.Sprite;
    public class main extends Sprite {
        public function main() {
            trace("Init");
        }
    }
}

When run under ADL, "Init" will be output to the console, but when installed and run, nothing happens (the constructor for class main is never called).

+1  A: 

The final air file runs in a release player and will not dispatch any traces. That's why you're not getting anything.

grapefrukt
Ah, that would make sense. Is the any other way then to log the activities of an installed application? My real application does not seem to fetching its data on startup when run as a standalone app, which is what led me to believe the main class was not being initalized.
SilverCode
It seems that even if I just try write to a file in the main class, nothing happens, so I still think that the main class constructor is never being called.
SilverCode
A: 

Here is the easiest way:

1) File - New - Flex Project

2) Give the app the name AIRActionScrip for this test project and choose AIR as the application type.

3) Click "Next" twice.

4) In the "Main application file:" text input, change the main application file extension from .mxml to .as.

5) Click "Finish" and you have an AIR app in ActionScript.

6) Edit the class definition as follows:

 package {
      import flash.desktop.NativeApplication;
  import flash.display.NativeWindow;
  import flash.display.NativeWindowInitOptions;
  import flash.display.Sprite;
  import flash.display.StageAlign;
  import flash.display.StageScaleMode;
  import flash.events.Event;
  public class AIRActionScript extends Sprite
  {
    public function AIRActionScript()
    {
      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);
    }
  }
}
Carlos Barbosa