AppMenu class

Menus are one of the most important methods to create better user experience and integrating with OS. And AIR platform supports both windows menu (on Windows) and application menu (on Mac OS) very well. The downside is implementing menus through the Action Script is too complex. You have to create NativeMenu instance, then attach NativeMenuItems and then do it again and and again to create simple menus. So I’ve developed “AppMenu” class which converts well-formed XML data to every type of menu that you want.

XML data must look like this:
[btcode title=’XML’ lang=’xml’]
<menu label="File" id="file">

<menu label="New" id="new" />

<menu label="Open" id="open">
<browse func="open" title="select a file to open…">
<filefilter description="Foo file (.foo)" extension="*.foo" />
<filefilter description="Bar file (.bar)" extension="*.bar" />

<menu label="Go to website" id="goToWebsite" href="" />

<menu label="Do Sth" id="doSth" fucn="toggleBool" />

<menu label="Close" id="close"/>

After that, create an instance of AppMenu class and pass XML data in constructor function…

[btcode title=’AS3′ lang=’java’]
var menusXml:XML = new XML(…);
var myMenu:AppMenu = new AppMenu(menusXml); = appMenu.myMenu;
To get a specific item, use AppMenu::getNmiById method…
[btcode title=’AS3′ lang=’java’]
myMenu.getNmiById(‘file.close’).addEventListener(Event.SELECT, closeApplication);
AppMenu on Github

Repository: AppMenu on Github
Programming Language: Action Script 3.0