Flex中如何利用Repeater组件载入XML并显示图片文件的例子

By Minidxer | October 13, 2008

接下来的例子演示了Flex中如何利用Repeater组件载入XML并显示图片文件。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="middle"
  5.         backgroundColor="white">
  6.  
  7.     <mx:XML id="imagesXML" source="images.xml" />
  8.  
  9.     <mx:Zoom id="zoom" />
  10.  
  11.     <mx:HBox id="hBox">
  12.          <mx:Repeater id="rep"
  13.                  dataProvider="{imagesXML.image}">
  14.             <mx:Image source="{rep.currentItem.@src}"
  15.                     toolTip="{rep.currentIndex}:{rep.currentItem.@alt}"
  16.                     completeEffect="{zoom}" />
  17.         </mx:Repeater>
  18.     </mx:HBox>
  19.  
  20. </mx:Application>

下面是XML定义:

Download: images.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <images>
  3.     <image src="images/Button.png" alt="Button" />
  4.     <image src="images/ButtonBar.png" alt="ButtonBar" />
  5.     <image src="images/CheckBox.png" alt="CheckBox" />
  6.     <image src="images/ColorPicker.png" alt="ColorPicker" />
  7.     <image src="images/ComboBox.png" alt="ComboBox" />
  8.     <image src="images/DataGrid.png" alt="DataGrid" />
  9.     <image src="images/DateChooser.png" alt="DateChooser" />
  10.     <image src="images/DateField.png" alt="DateField" />
  11. </images>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: XML | Tags: , , , , ,

Related Post

Leave a Comment

Name(*):

E-Mail(*) :

Website :

Comments :

Search Posts

Archives

Sponsored Ads