Adding icon to Menuitem
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import mx.controls.Menu;
[Bindable]
[Embed(source="logo.jpg")]
public var myTopIcon:Class;
[Bindable]
[Embed(source="logo.jpg")]
public var myRadioIcon:Class;
[Bindable]
[Embed(source="logo.jpg")]
public var myCheckIcon:Class;
private function createAndShow():void {
var myMenu:Menu = Menu.createMenu(null, myMenuData, false);
myMenu.labelField="@label";
myMenu.setStyle('checkIcon', myCheckIcon);
myMenu.setStyle('radioIcon', myRadioIcon);
myMenu.iconField="@icon";
myMenu.show(10, 10);
}
</mx:Script>
<mx:XML format="e4x" id="myMenuData">
<root>
<menuitem label="MenuItem A" icon="myTopIcon">
<menuitem label="A-1" enabled="False" />
<menuitem label="A-2" />
<menuitem label="A-3" />
<menuitem label="A-4" />
<menuitem label="A-5" />
</menuitem>
<menuitem label="MenuItem B" type="check" toggled="true" />
<menuitem label="MenuItem C" type="check" toggled="false" icon="myTopIcon" />
<menuitem type="separator" />
<menuitem label="MenuItem D" icon="myTopIcon">
<menuitem label="D-1" type="radio" groupName="one" />
<menuitem label="D-2" type="radio" groupName="one" toggled="true" />
<menuitem label="D-3" type="radio" groupName="one" />
</menuitem>
</root>
</mx:XML>
<mx:VBox>
<mx:Button id="myButton" label="Open Menu" click="createAndShow();" />
</mx:VBox>
</mx:Application>
Related examples in the same category