New with Flex and mxml. How I can bind AS3 class’ function to a menubar item? My menubar code is this:
<mx:MenuBar id="myMenubar" labelField="@label">
<fx:XMLList xmlns="">
<item label="File">
<item label="New" />
<item label="Open"/>
<item label="Save"/>
<item label="Save As"/>
<item label="Quit"/>
</item>
<item label="Edit">
<item label="Undo"/>
<item label="Redo"/>
<item label="Preferences"/>
</item>
<item label="Level">
<item label="New Room"/>
<item label="Properties"/>
</item>
<item label="Objects">
<item label="Clickable"/>
<item label="Character"/>
<item label="Door"/>
<item label="Treasure"/>
</item>
</fx:XMLList>
</mx:MenuBar>
I looked through few examples in Google but couldn’t find definite explanation or example how to trigger AS3 class functions. I presume that I should somehow make click event listener for my subitems and make a call to my class. However, mxml syntax confuses me.
MXMLis just a way to describe data and components declaratively, in the end it’s compiled to pure ActionScript anyways, so you can simply subscribe an appropriate listener tomyMenubar.I think you are looking for the
itemClickevent:In order to be able to distinguish the items while being able to change the lablels, i’d recommend to assign IDs to them:
Then you could for example use a simple switch to handle the different items:
Ofcourse you could also define which function to call using
MXML:–
See also the example in the Adobe LiveDocs to get a grasp on how this all comes together: