6 Replies Latest reply on Dec 21, 2009 4:11 PM by heavyboots

    Can't disable nativemenu item

    jshrek Level 1

      I am trying to disable an item on the nativemenu I created, but I can't seem to figure out the correct way to do it. I am using JavaScript in Win XP Pro:


      Here is the menu XML:

      <?xml version="1.0" encoding="utf-8" ?>
          <menuitem label="File">
              <menuitem label="Close" onSelect="doFileClose"/>
          <menuitem label="Help">
              <menuitem label="About" onSelect="doHelpAbout"/>


      And here is how I succesfully create the menu:

      var _MainMenu = air.ui.Menu.createFromXML("source/MainMenu.xml");
      air.ui.Menu.setAsMenu(_MainMenu, true);


      I am trying to disable the HELP item, but can't quite figure it out... I tried:

      air.ui.Menu.Item("Help").enabled = false;


      and also

      air.NativeMenuItem("Help").enabled = false;


      and also

      air.ui.Menu.NativeMenuItem("Help").enabled = false;


      Any suggestions appreciated!


        • 1. Re: Can't disable nativemenu item
          heavyboots Level 2

          You've assigned the menu bar to _MainMenu. Something like this should work after that line:


          _MainMenu.getItemByName("Help").enabled = false;


          Also, if you need to get to items in a submenu (ie, only disable "About"), try this format:


          _MainMenu.getItemByName("Help").submenu.getItemByName("About").enabled = false;

          1 person found this helpful
          • 2. Re: Can't disable nativemenu item
            jshrek Level 1

            Thanks for reply, but that does not work


            If I use this:



            I get this:

            [object NativeMenu]


            If I use this:



            I get this:




            So _MainMenu appears to be defined, but the menu items do not appear to be accessible by Name.


            Any other suggestions?



            • 3. Re: Can't disable nativemenu item
              heavyboots Level 2

              I've never used the createFromXML method. It could be the name for each item is "menuitem". You could try trace(_MainMenu.submenu) and see what comes back from that. Alternatively, this might have the desired effect:


              _MainMenu.getItemAt(1).enabled = false;


              (Search help for flash.display.NativeMenu for more methods to access menus & submenus.)

              1 person found this helpful
              • 4. Re: Can't disable nativemenu item
                jshrek Level 1

                Just in case it was missed, I am trying to use JavaScript, not Flash or Flex, so I don't know if these findings below apply to flash or flex... but they definitely do apply to JavaScript. I am also using v1.5.3 of the AIR SDK on Windows XP Pro for anybody else that might be wondering.


                But okay, I figured out how to use the AIR Introspector, and after some long searching thru everything in the DOM, I found the following:


                (1) _MainMenu does not appear to be defined anywhere in the DOM which means you cannot access it directly by it's name.


                (2) To access the properties of the native menu, you need to use ITEMS:

                window.nativeWindow.menu.items[X].enabled = false   or

                window.nativeWindow.menu.items[X].submenu.items[Y].enabled = false


                (3) I also noticed that the window.nativeWindow.menu.getItemByName and getItemAt property are both also NULL and cannot be used. You have to loop thru all the items to find the one with the appropriate label:

                window.nativeWindow.menu.items[X].label = "Help"


                Here is an example on how to disable a top level menu item:

                length = window.nativeWindow.menu.items.length; //How many top level menu items

                for (i=0; i<length; i++) {

                     if (window.nativeWindow.menu.items.label = "Help") { //Check to see which menu item it is

                          window.nativeWindow.menu.items[i].enabled = false //



                • 5. Re: Can't disable nativemenu item
                  jshrek Level 1


                  heavyboots for your answers... they got me looking in the right place!
                  • 6. Re: Can't disable nativemenu item
                    heavyboots Level 2

                    Er, glad to help... (And thanks for being so thorough in your answer!)


                    And sorry I didn't key in the fact you were doing JS not Flash-based...