3 Replies Latest reply on Dec 23, 2010 7:21 AM by jfb00

    Menu item

    jfb00 Level 3

      Hi,

      In my menu sample bellow, how can I refer to my menu item "menuNew" or label "New Item" from my initial function? I would like to change the "enabled" property base in some conditions.

      I try menuNew.enabled = false; but I got error: 1120: Access of undefined property menuNew.   
      Any ideas?

      Thanks

       

      Johnny

       

      <mx:MenuBar id="myMenu" showRoot="false" labelField="@label" iconField="@icon" cornerRadius="10" itemClick="menuClickHandler(event)">
              <mx:XML>
                  <menuitem id="rootMenu">
                      <menuitem label="File">
                          <menuitem id="menuNew" label="New Item"/>
                          <menuitem label="Open"/>
                      </menuitem>
                      <menuitem label="Edit">
                          <menuitem id="cut" label="Cut"/>
                          <menuitem id="copy" label="Copy"/>
                          <menuitem id="paste" name="paste" label="Paste" enabled="false"/>
                          <menuitem type="separator" />
                          <menuitem label="Other menu item"/>
                      </menuitem>
                      <menuitem id="windowMenu" label="Window">
                          <menuitem id="d1"           label="Document 1" type="radio" group="docs" toggled="false"/>
                          <menuitem                   label="Document 2" type="radio" group="docs" toggled="true"/>
                          <menuitem id="d3" name="d3" label="Document 3" type="radio" group="docs" toggled="false"/>
                          <menuitem                   label="Document 4" type="radio" group="docs" toggled="false"/>
                      </menuitem>
                  </menuitem>
              </mx:XML>
          </mx:MenuBar>
      
        • 1. Re: Menu item
          smanisankar

          It depends on where you have written your script, try the same code after creationComplete..it should be working fine.

          • 2. Re: Menu item
            jfb00 Level 3

            Hi,

            Thanks for you reply and help but it is not working.

            I try using creationComplete in the menu and in the application calling a function like:

             

            private function init():void{
                            this.menuNew.enabled = true;
                        }
            
            <mx:MenuBar id="myMenu" showRoot="false" labelField="@label" iconField="@icon" cornerRadius="10"
            itemClick="menuClickHandler(event)" creationComplete="init()">
            

             


            Any other ideas?

            Rgds

             

            Johnny

            • 3. Re: Menu item
              jfb00 Level 3

              I got it,

              myMenu.dataProvider.source[0].menuitem[1].menuitem[1].@enabled = false;

               

              Johnny