1:数组Array
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]public var menuDataTypeArray : Array =
[
{label:'File',children:[ { label:'New' }, { label:'Open' } ] },
{label:'Edit',children:[{label:'Undo'},{label:'Redo'}]}
];
]]>
</fx:Script>>
<mx:MenuBar dataProvider="{menuDataTypeArray}"/>
嵌套数组默认是查找名为children的嵌套数组
2:ArrayCollection
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]public var menuDataTypeArray : Array =
[
{label:'File',children:[ { label:'New' }, { label:'Open' } ] },
{label:'Edit',children:[{label:'Undo'},{label:'Redo'}]}
];
[Bindable]private var menuDataTypeArrayList:ArrayCollection = new ArrayCollection(menuDataTypeArray);
]]>
</fx:Script>
<mx:MenuBar dataProvider="{menuDataTypeArrayList}" />
3:使用MXML标签<fx:Array>
<fx:Array id="menuData">
<fx:Object label="File">
<fx:children>
<fx:Array>
<fx:Object label="Start"/>
</fx:Array>
</fx:children>
</fx:Object>
</fx:Array>
ArrayCollection 包装
<mx:ArrayCollection id="menuData">
<fx:Array >
<fx:Object label="File">
<fx:children>
<fx:Array>
<fx:Object label="Start"/>
</fx:Array>
</fx:children>
</fx:Object>
</fx:Array>
</mx:ArrayCollection>
4:XML
<fx:XML id="menuDataXML">
<root>
<menuitem label="File">
<submenu label="New" />
<submenu label="Edit"/>
</menuitem>
<menuitem label="View">
<submenu label="View1"/>
</menuitem>
</root>
</fx:XML>
<mx:MenuBar dataProvider="{menuDataXML}" labelField="@label" showRoot="false"/>
也可以通过actionscript实现
5:XMLList
<fx:XMLList id="menuDataXML">
<menuitem label="File">
<submenu label="New" />
<submenu label="Edit"/>
</menuitem>
<menuitem label="View">
<submenu label="View1"/>
</menuitem>
</fx:XMLList>
<mx:MenuBar dataProvider="{menuDataXML}" labelField="@label" />
也可以通过actionscript实现
6:XMLListCollection
<mx:XMLListCollection id="menuDataXML">
<fx:XMLList>
<menuitem label="File">
<submenu label="New" />
<submenu label="Edit"/>
</menuitem>
<menuitem label="View">
<submenu label="View1"/>
</menuitem>
</fx:XMLList>
</mx:XMLListCollection>
<mx:MenuBar dataProvider="{menuDataXML}" labelField="@label" />
也可以通过actionscript实现