Adobe Air: add NativeMenuItem to existing NativeMenu

December 2, 2009 by fMajakovskij

If you want to add just a single (or more) custom NativeMenuItem on the your existing NativeMenu, you can do it without recreate all the NativeMenu structure.

Just write down something like:


// get the NativeMenu object
var nm:NativeMenu = NativeApplication.nativeApplication.menu

// I want to use the first menuItem, so use the index=0
var nm0:NativeMenuItem = nm.getItemAt(0)

// create the custom NativeMenuItem
var prefMenu:NativeMenuItem = new NativeMenuItem("Preferences...");
prefMenu.addEventListener(Event.SELECT, openPrefWin);
var separator:NativeMenuItem = new NativeMenuItem("separator", true);

// add it to our existing NativeMenu
// these menu will placed immediately after the 'About' menuItem
nm0.submenu.addItemAt(separator, 1)
nm0.submenu.addItemAt(prefMenu, 2)

That’s it

One thought on “Adobe Air: add NativeMenuItem to existing NativeMenu

  1. TheDarkIn1978 says:

    thank you! you’ve relieved my headache.

    this process is very unclear. instead of rerouting thru the submenu property it would be more clear if adobe supplied a getSubmenu and getSubmenuAt methods in the NativeMenu class.

    thanks again!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>