1 Reply Latest reply on Jan 19, 2009 7:49 AM by iqdev

    OS X Native Application Menu initialization

    stackfour20
      This simple native application menu on OS X sometimes work and sometimes doesn't, both within ADL and as a standalone AIR application. At startup time, it appears that the event handler is not always properly installed. When it is, selecting the File->Open menu item will always call the handler. When it is not, the handler will never be called though the menu item exists and can be selected. A single SWF file generated by the compiler can yield both behaviors.

      Are there potential race conditions at startup I need to be aware of?
      Does native application menu manipulation need to done elsewhere?

      I'm using the 3.0.2.2113 build of the SDK on OS X 10.5.4.

      Compilation command:
      /Users/XXXX/flex/sdk/3.0.2.2113/flex_sdk_3/bin/mxmlc +configname=air toto.as
      Loading configuration file /Users/XXXX/flex/sdk/3.0.2.2113/flex_sdk_3/frameworks/air-config.xml
      /Users/XXXX/flex/toto/toto.swf (927 bytes)

      AS3 code:
      package {
      import flash.desktop.NativeApplication;
      import flash.display.NativeWindow;
      import flash.display.NativeMenu;
      import flash.display.NativeMenuItem;
      import flash.display.Sprite;
      import flash.events.Event;

      public class toto extends Sprite
      {
      public function toto()
      {
      addEventListener(Event.ADDED_TO_STAGE, display);
      init();
      }

      private function display(event:Event):void
      {
      var win:NativeWindow = stage.nativeWindow;

      trace("display");
      win.height = 200;
      win.width = 200;
      win.visible = true;
      }

      private function init():void
      {
      var root:NativeMenu;
      var file:NativeMenuItem;
      var open:NativeMenuItem;

      trace("init");

      if (NativeApplication.supportsMenu) {
      root = NativeApplication.nativeApplication.menu;

      file = root.getItemAt(1);
      open = file.submenu.addItem(new NativeMenuItem("Open"));
      open.addEventListener(Event.SELECT, fileOpen);
      }
      }

      private function fileOpen(event:Event):void
      {
      trace("file open");
      }
      }
      }

      App description:
      <?xml version="1.0" encoding="UTF-8"?>
      <application xmlns=" http://ns.adobe.com/air/application/1.0">
      <id>stackfour20.flex.toto</id>
      <version>0.1</version>
      <filename>toto</filename>
      <name>toto</name>

      <initialWindow>
      <title>toto</title>
      <content>toto.swf</content>
      <systemChrome>standard</systemChrome>
      <visible>false</visible>
      </initialWindow>
      </application>