3 Replies Latest reply on Aug 12, 2008 8:25 AM by ericbelair

    Context menus with sub menus

    MattFlex3
      I'm newbie in Flex, i try to do a Context menu with sub menus but i can't only i can do simple context menu, any can help me to do that?

      This is my code:
      I need that the open of the menu will be directly
      <?xml version="1.0"?>
      <!-- menus/SimpleMenuControl.mxml -->
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">

      <mx:Script>
      <![CDATA[
      // Import the Menu control.
      import mx.controls.Menu;

      import flash.ui.ContextMenu;
      import flash.ui.ContextMenuBuiltInItems;
      import flash.events.ContextMenuEvent;
      private var fsCM:ContextMenu;
      private var fs:ContextMenuItem;
      // Create and display the Menu control.
      private function init():void {
      fsCM = new ContextMenu();
      fs = new ContextMenuItem("Context");
      fs.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, Sns);
      fsCM.customItems.push(fs);
      this.contextMenu = fsCM;
      }


      private function Sns(event:ContextMenuEvent):void{
      var myMenu:Menu = Menu.createMenu(null, myMenuData, false);
      myMenu.labelField="@label";
      myMenu.show(10, 10);
      }
      ]]>
      </mx:Script>

      <!-- Define the menu data. -->
      <mx:XML format="e4x" id="myMenuData">
      <root>
      <menuitem label="MenuItem A" >
      <menuitem label="SubMenuItem A-1" enabled="false"/>
      <menuitem label="SubMenuItem A-2"/>
      </menuitem>
      <menuitem label="MenuItem B" type="check" toggled="true"/>
      <menuitem label="MenuItem C" type="check" toggled="false"/>
      <menuitem type="separator"/>
      <menuitem label="MenuItem D" >
      <menuitem label="SubMenuItem D-1" type="radio"
      groupName="one"/>
      <menuitem label="SubMenuItem D-2" type="radio"
      groupName="one" toggled="true"/>
      <menuitem label="SubMenuItem D-3" type="radio"
      groupName="one"/>
      </menuitem>
      </root>
      </mx:XML>

      <mx:VBox>
      <!-- Define a Button control to open the menu -->
      <mx:Button id="myButton1"
      label="Open Menu"
      />
      </mx:VBox>
      <mx:LinkButton id="myButton" click="init()" label="LinkButton"/>
      </mx:Application>