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

Submenus

It's time to get a little fancier. How do you add submenus to get something like Figure 28.5?

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({label:"Open",
						instanceName:"openItem"});
						// add submenus
						var openMenuItem = button.menu.getItemAt(0);
						openMenuItem.addMenuItem("Recent");
						openMenuItem.addMenuItem("Recovered");

      // this also works
      //button.menu.openItem.addMenuItem("Recent");
      //button.menu.openItem.addMenuItem("Recovered");

      // so does this:
      // button.menu["openItem"].addMenuItem("Recent");
      // button.menu["openItem"].addMenuItem("Recovered");

      // this has no effect
      //button.menu.getItemAt(1).addMenuItem("Recovered");

      button.menu.addMenuItem({ label:"Close", instanceName:"close"} );
      button.menu.addMenuItem({ type:"separator" });
      button.menu.addMenuItem({ label:"Save", instanceName:"save"} );
      button.menu.addMenuItem({label:"Revert",instanceName:"revert"} );

      // Add a change-listener to catch item selections
      var changeListener = new Object();
      changeListener.change = function(event)
      {
         var item = event.menuItem;
         // do something on change, if you want
        }
        button.menu.addEventListener("change", changeListener);
    }
   button.menu.show(button.x, button.y + button.height);
}
command_btn.addEventListener("click", listener);


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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