开发者

Pure Actionscript 3 Adobe Air Application main class constructor not being called

I'm writing an Air application using only A开发者_如何转开发ctionscript, 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).


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


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);
    }
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜