j b
j b

Reputation: 5296

How do I append submenus to an existing FlexNativeMenu instance?

I'm completely confused by this. An Adobe Flex WindowedApplication has a 'menu' property, which by default is assigned a FlexNativeMenu instance, which is used to create a native menu tree for the application.

For example, on OS X, if I create a WindowedApplication, I get the standard 'application menu', 'File', 'Edit' and 'Window' menus created on startup.

The question is, how do I append additional menus to this without creating an entirely new menu? I want to use the default OS X menus as a starting point and add my own.

If I assign menu = new FlexNativeMenu; I just get a completely empty application bar with no menus at all.

Upvotes: 1

Views: 428

Answers (1)

NoobsArePeople2
NoobsArePeople2

Reputation: 1996

This is going to work differently for Windows and Mac OS. My code looks something like this:

if (isWindows)
{
   // Windows lacks a menu by default, create one.
   menu = new NativeMenu();
}
else if (isMac)
{
   // Mac OS has a default menu, get a reference to it.
   menu = NativeApplication.nativeApplication.menu;
}

buildMenu(menu);

The buildMenu() function then does a bunch of work to build the menu.

function buildMenu(menu:NativeMenu):NativeMenu
{
    var menuItem:NativeMenuItem = menu.addItem(new NativeMenuItem("Menu Label"));
    var menuItem.name = "menuLabelName";
    var menuItem.data = myDataForThisMenuItem;
    menuItem.subMenu = buildSubMenu();

    return menu;
}

function buildSubMenu():NativeMenu
{
    var subMenu:NativeMenu = new NativeMenu();
    var menuItem:NativeMenuItem;

    menuItem = subMenu.addItem(new NativeMenuItem("Sub Menu Label"));
    menuItem.name = "subMenuName";
    menuItem.data = subMenuData;

    return subMenu;
}

Upvotes: 1

Related Questions