• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 28. Menu Component > Types of Menu Items

Types of Menu Items

Two other menu types you can use are checkbox items (items you can toggle on and off, like View → Rulers) and radio items—only one in a group can be chosen. Here's some code that adds these items to our menu (and a little something else).

var listener = new Object();
listener.click = function(evtObj)
   var button = evtObj.target;
   if(button.menu == undefined)
      // Create a Menu instance and add some items
      button.menu = mx.controls.Menu.createMenu();
      button.menu.addMenuItem({ type:"separator" });

      // doesn't result in anything that looks like a radio button
						// you have to open the menu again to see the little radio
						// button. Placing menu items in a radio group ensures that
						// only one of them is selected
						button.menu.addMenuItem({ label:"Item r1", type:"radio",
						selected:false, enabled:true, instanceName:"radioItem1",
						groupName:"myRadioGroup" } );
						button.menu.addMenuItem({ label:"Item r2", type:"radio",
						selected:false, enabled:true, instanceName:"radioItem2",
						groupName:"myRadioGroup" } );
						 button.menu.addMenuItem({ label:"Item r3", type:"radio",
						selected:false, enabled:true, instanceName:"radioItem3",
						groupName:"myRadioGroup" } );
						// checkbox menu items can be all on or all off
						button.menu.addMenuItem({ label:"Item c1", type:"check" } );
						button.menu.addMenuItem({ label:"Item c2", type:"check" } );
						button.menu.addMenuItem({ label:"Item c3", type:"check" } );
						// Add a change-listener to catch item selections
						var changeListener = new Object();
						changeListener.change = function(event)
						var item = event.menuItem;
						trace("Item selected:  " + item.attributes.label);
						button.menu.addEventListener("change", changeListener);
   // here's where the menu actually appears
   button.menu.show(button.x, button.y + button.height);
command_btn.addEventListener("click", listener);




Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint