Behrooz
Tahanzadeh


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’]
<app>
<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" />
</browse>
</menu>

<menu label="Go to website" id="goToWebsite" href="http://foo.com" />

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

<menu label="Close" id="close"/>
</menu>
</app>
[/btcode]

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);
stage.nativeWindow.menu = appMenu.myMenu;
[/btcode]
To get a specific item, use AppMenu::getNmiById method…
[btcode title=’AS3′ lang=’java’]
myMenu.getNmiById(‘file.close’).addEventListener(Event.SELECT, closeApplication);
[/btcode]
AppMenu on Github


Repository: AppMenu on Github
Programming Language: Action Script 3.0