Tag Archives: AIR

第一个Air小程序

开发给公司的课件合成人员使用,主要功能是实现了对大量包含时间点的xml文件的分析处理,可以减少花在上面的重复劳动时间。
采用flash cs3开发,涉及文件的查找,读写,字符,xml的处理。

AIR NativeWindow 窗口控制

几个重点:
1、AIR默认会生成一个主窗口,可以用this.stage.nativeWindow获得对主窗口的引用;
2、AIR程序可生成多个窗口,并使用addChild向窗口添加内容;
3、窗口colse后就不能在重新打开了,只能从新构造窗口,或者使用visible方式是窗口暂时不显示;
4、主窗口的初始设置是在app.xml文件里完成的,新建窗口要使用NativeWindowInitOptions进行窗口初始化设置

代码如下:

下载: window.as
  1. package {
  2.  
  3. import flash.display.MovieClip;
  4.  
  5. import flash.display.NativeWindow;
  6.  
  7. import flash.display.NativeWindowInitOptions;
  8.  
  9. import flash.display.NativeWindowType;
  10.  
  11. import flash.events.MouseEvent;
  12.  
  13. public class testWindow extends MovieClip {
  14.  
  15. private var myBox1:MovieClip;
  16.  
  17. private var myBox2:MovieClip;
  18.  
  19. private var mainWin:NativeWindow;
  20.  
  21. private var window:NativeWindow;
  22.  
  23. public function testWindow() {
  24.  
  25.  
  26.  
  27. myBox1 = new box();
  28.  
  29. myBox2 = new box();
  30.  
  31. mainWin = stage.nativeWindow;
  32.  
  33. with (myBox1) {
  34.  
  35. x=100;
  36.  
  37. y=100;
  38.  
  39. alpha=.5;
  40.  
  41. }
  42.  
  43. with (myBox2) {
  44.  
  45. x=400;
  46.  
  47. y=100;
  48.  
  49. //alpha=.5;
  50.  
  51. }
  52.  
  53. mainWin.stage.addChild(myBox1);
  54.  
  55. mainWin.stage.addChild(myBox2);
  56.  
  57. myBox1.addEventListener(MouseEvent.CLICK,clickHandler1);
  58.  
  59. myBox2.addEventListener(MouseEvent.CLICK,clickHandler2);
  60.  
  61. }
  62.  
  63. private function clickHandler1(event:MouseEvent):void {
  64.  
  65. var options:NativeWindowInitOptions = new NativeWindowInitOptions();
  66.  
  67. options.type = NativeWindowType.UTILITY;
  68.  
  69. if (!window||window.closed) {
  70.  
  71. window = new NativeWindow(options);
  72.  
  73. window.width = 200;
  74.  
  75. window.height = 200;
  76.  
  77. window.activate();
  78.  
  79. }
  80.  
  81. }
  82.  
  83. private function clickHandler2(event:MouseEvent):void {
  84.  
  85. if (!window.closed) {
  86.  
  87. window.width += 100;
  88.  
  89. window.height += 100;
  90.  
  91. }
  92.  
  93. }
  94.  
  95. }
  96.  
  97. }