Flex中如何利用Repeater组件载入XML并显示图片文件。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white">
-
- <mx:XML id="imagesXML" source="images.xml" />
-
- <mx:Zoom id="zoom" />
-
- <mx:HBox id="hBox">
- <mx:Repeater id="rep"
- dataProvider="{imagesXML.image}">
- <mx:Image source="{rep.currentItem.@src}"
- toolTip="{rep.currentIndex}:{rep.currentItem.@alt}"
- completeEffect="{zoom}" />
- </mx:Repeater>
- </mx:HBox>
-
- </mx:Application>
下面是XML定义:
Download: images.xml
- <?xml version="1.0" encoding="utf-8"?>
- <images>
- <image src="images/Button.png" alt="Button" />
- <image src="images/ButtonBar.png" alt="ButtonBar" />
- <image src="images/CheckBox.png" alt="CheckBox" />
- <image src="images/ColorPicker.png" alt="ColorPicker" />
- <image src="images/ComboBox.png" alt="ComboBox" />
- <image src="images/DataGrid.png" alt="DataGrid" />
- <image src="images/DateChooser.png" alt="DateChooser" />
- <image src="images/DateField.png" alt="DateField" />
- </images>