List.mxml<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="*"> <!-- Model标签主要用于数据,Model定义的数据编译被转化为一般的ActionScript数据对像, 可以用作数据绑定。不同的是,这些数据不可以被更改,没有明确的数据类型,可以是字符串,整型,XML数据等。 --> <mx:Model id="images"> <image> <item label="图片1" data="C:MyProject lexProjectimages/1.gif"></item> <item label="图片2" data="C:MyProject lexProjectimages/2.gif"></item> <item label="图片3" data="C:MyProject lexProjectimages/3.gif"></item> <item label="图片4" data="C:MyProject lexProjectimages/4.gif"></item> </image> </mx:Model> <mx:List x="72" y="62" dataProvider="{images.item}" itemRenderer="ImageItem"></mx:List> <!-- images.item包含了XML数据中所有节点为“item”的数据,并通过dataProvider属性将数据传递给List组件 --> <!-- itemRenderer="ImageItem"表示用自定义的itemRenderer来代替默认的组件,ImageItem就是自定义的组件 --></mx:Application>ImageItem.mxml<?xml version="1.0" encoding="utf-8"?><mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" width="102" height="54"> <mx:Image width="39" height="41" source="{data.data}"/> <mx:Button label="{data.label}" width="54" height="40"/> <!-- flex通过data属性,将数据传递给itemRenderer的,在自定义的itemRenderer中,直接调用data对像的属性就可以了,但itemRenderer并不对数据进行有效的验证 --></mx:HBox>