1 List
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> <mx:List id="myFriends" x="10" y="10"> <fx:String>Ely Green</fx:String> <fx:String>Ryan Stewart</fx:String> <fx:String>Serge Jespers</fx:String> </mx:List> </s:Application>
2 List 调用的数据单独使用 dataProvider,放在 arrayCollection
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> <fx:Declarations> <s:ArrayCollection id="myAc"> <fx:Object label="中国"/> <fx:Object label="朝鲜"/> <fx:Object label="伊朗"/> </s:ArrayCollection> </fx:Declarations> <mx:List id="myFriends" x="10" y="10" dataProvider="{myAc}" /> </s:Application>
3 制定标签使用 labelField
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; [Bindable] public var myAC:ArrayCollection = new ArrayCollection([ {name:"中国",email:"1@a.cn",url:"http://baidu.com"}, {name:"上海",email:"1@a.cn",url:"http://baidu.com"}, {name:"北京",email:"1@a.cn",url:"http://baidu.com"} ]); ]]> </fx:Script> <s:layout> <s:HorizontalLayout> </s:HorizontalLayout> </s:layout> <mx:List id="myFriends" dataProvider="{myAC}" labelField="name" /> <mx:List id="myEmail" dataProvider="{myAC}" labelField="email" /> <mx:List id="myWeb" dataProvider="{myAC}" labelField="url" /> </s:Application>
4
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; [Bindable] public var myAC:ArrayCollection = new ArrayCollection([ {name:"中国",email:"1@a.cn",url:"http://baidu.com"}, {name:"上海",email:"1@a.cn",url:"http://baidu.com"}, {name:"北京",email:"1@a.cn",url:"http://baidu.com"} ]); ]]> </fx:Script> <s:layout> <s:VerticalLayout/> </s:layout> <mx:HorizontalList id="myFriends" dataProvider="{myAC}" labelField="name"/> <mx:HorizontalList id="myEmail" dataProvider="{myAC}" labelField="email" /> <mx:HorizontalList id="myWeb" dataProvider="{myAC}" labelField="url" /> </s:Application>
5
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; [Bindable] public var myAC:ArrayCollection = new ArrayCollection([ {name:"中国",email:"1@a.cn",url:"http://baidu.com"}, {name:"上海",email:"1@a.cn",url:"http://baidu.com"}, {name:"北京",email:"1@a.cn",url:"http://baidu.com"} ]); ]]> </fx:Script> <s:layout> <s:VerticalLayout/> </s:layout> <mx:TileList id="myFriends" dataProvider="{myAC}" labelField="name" direction="horizontal"/> <mx:TileList id="myEmail" dataProvider="{myAC}" labelField="email" direction="vertical"/> <mx:TileList id="myWeb" dataProvider="{myAC}" labelField="url" columnWidth="150"/> </s:Application>
6 dataGrid
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> <mx:DataGrid id="dg" width="500" height="200"> <mx:dataProvider> <fx:Object name="朝鲜" email="t1riq@domain.com" a金额="10000"/> <fx:Object name="中国" email="t2riq@domain.com"/> <fx:Object name="台湾" email="t3riq@domain.com"/> </mx:dataProvider> </mx:DataGrid> </s:Application>
7 dataProvider 外部数据填充
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; [Bindable] public var myAC:ArrayCollection = new ArrayCollection([ {name:"中国", email:"dang@mai.com",url:"http://danorl.com"}, {name:"朝鲜", email:"dang@mai.com",url:"http://danorl.com"}, {name:"马里亚纳", email:"dang@mai.com",url:"http://danorl.com"} ]); ]]> </fx:Script> <mx:DataGrid id="dg" width="500" height="150" dataProvider="{myAC}"> <mx:columns> <mx:DataGridColumn dataField="name" headerText="你的名字" width="100"/> <mx:DataGridColumn dataField="email" headerText="邮箱" width="300"/> <mx:DataGridColumn dataField="url" headerText="网站" width="200"/> </mx:columns> </mx:DataGrid> </s:Application>
8 Tree
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> <fx:Declarations> <mx:XMLListCollection id="myXMLCollection"> <fx:XMLList id="myXML" xmlns=""> <friends label="Friends"> <friend label="小胡"/> <friend label="小朱"/> <friend label="小习"/> <friend label="小李"/> </friends> <families label="Family"> <family label="施瓦辛格"/> <family label="是哇是哇"/> </families> </fx:XMLList> </mx:XMLListCollection> </fx:Declarations> <mx:Tree dataProvider="{myXMLCollection}" labelField="@label" width="300" height="400"/> </s:Application>
9 通过向函数传递事件对象来处理用户交互
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; import mx.controls.Alert; import mx.events.ListEvent; [Bindable] public var myAC:ArrayCollection = new ArrayCollection([ {name:"小溪",email:"当当@dang.com"}, {name:"小里",email:"立刻@dang.com"}, {name:"小yuan",email:"a立刻@dang.com"} ]); public function contactDatGrid_clickHandler(event:ListEvent):void { Alert.show("你点击的这一行:"+event.rowIndex+"这一列:"+event.columnIndex+" 是 "+ event.currentTarget.selectedItem.name+"邮箱:"+ event.currentTarget.selectedItem.email); } ]]> </fx:Script> <mx:DataGrid id="contactDataGrid" width="500" height="200" dataProvider="{myAC}" itemClick="contactDatGrid_clickHandler(event)"> <mx:columns> <mx:DataGridColumn dataField="name" headerText="名字" width="300"/> <mx:DataGridColumn dataField="email" headerText="电子邮件" width="200"/> </mx:columns> </mx:DataGrid> </s:Application>
10 ButtonBar
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> <s:layout> <s:VerticalLayout paddingLeft="20" paddingTop="20"/> </s:layout> <s:ButtonBar> <s:ArrayCollection> <fx:String>按钮1</fx:String> <fx:String>按钮2</fx:String> <fx:String>按钮3</fx:String> <fx:String>按钮4</fx:String> </s:ArrayCollection> </s:ButtonBar> </s:Application>