3 Replies Latest reply on Feb 28, 2008 11:09 PM by gpasq

    NativeMenu.addItem failing

    gpasq
      Ok, I'm a newb at this... Air (newly released version) installed on OS-X, running with Aptana IDE.

      The following code fails at the last line. The error is "TypeError: Value undefined (result of expression fileMenu.addItem) is not object."

      ANY ideas would be appreciated, I'm at a loss.

      Thanks in advance!

      var root = new air.NativeMenu();
      air.NativeApplication.nativeApplication.menu = root;

      var fileMenu = root.addSubmenu(new air.NativeMenu(), "File");
      air.trace(fileMenu);

      var quitCommand = new air.NativeMenuItem("Quit");
      quitCommand.addEventListener(air.Event.SELECT, selectCommand);
      air.trace(quitCommand);

      fileMenu.addItem(quitCommand);
        • 1. Re: NativeMenu.addItem failing
          Oliver Goldman Adobe Employee
          That's because addSubmenu() returns a NativeMenuItem, not a NativeMenu. To access its submenu, use fileMenu.submenu.

          See http://livedocs.adobe.com/air/1/devappshtml/help.html?content=Menus_3.html for more.

          Oliver Goldman | Adobe AIR Engineering

          • 2. Re: NativeMenu.addItem failing
            gpasq Level 1
            Thanks, but I guess I'm not following... where does my example differ from the example in the doc? (I actually copied it from there and just changed the names of the items).

            First part I create the root.

            Then I add a "File" submenu to the root.

            Then I create a "Quit" command and (try to) add it to the file submenu, and that's where it fails.

            If I change the last line to "fileMenu.subMenu.addItem(quitCommand);" It still fails, but with "TypeError: Undefined value"


            • 3. Re: NativeMenu.addItem failing
              gpasq Level 1
              Ok, I figured it out, but I used thte ColorMenu example instead. I still cannot get the main example (the referenced one) to work.

              So to sum up, a menu does NOT have a submenu with a label.... a menu has a menu item with a submenu. Got it.

              One other problem... keep in mind that I'm on a Mac... it seems that my root menu doesn't "activate" (i.e. show up as the "current application menu") when I put focus on the app. Instead, it shows up after the first alert shows.

              I'll try to track this down in the morning, but if you have any suggestions, I'd appreciate them.

              Thanks!