Repeater组件在重复制作一些简单用户界面组件上是很有用的。比如单选按钮。Repeater组件还可以用来效仿For循环。和asp.net里的Repeater挺像的。
【例1】:
MXML如下:
[codes=xml]<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" width="320" height="200">
<mx:Script>
<![CDATA[
[Bindable]
public var myArray:Array=[1,2,3,4];
]]>
</mx:Script>
<mx:Panel paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10" title="Repeater emulating a for loop--And8.net" borderColor="#00ff00">
<!--注意绝对定位和相对定位-->
<mx:Repeater id="myRepeater" dataProvider="{myArray}">
<mx:Label id="myLabel" text="This is NO.{myRepeater.currentIndex}"/>
</mx:Repeater>
</mx:Panel>
</mx:Application>
[/codes]
【例2】:
MXML如下:
[codes=xml]<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" width="320" height="200">
<mx:ArrayCollection id="productsAC">
<mx:Object name="Whirlygig" price="5" freeship="false"/>
<mx:Object name="Tilty Thingy" price="15" freeship="true"/>
<mx:Object name="Really Big Blocks" price="25" freeship="true"/>
</mx:ArrayCollection>
<mx:Panel title="Emulating for..in loops--And8.net" paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10" borderColor="#00ff00">
<mx:Repeater id="productsRepeater" dataProvider="{productsAC}">
<mx:RadioButton id="buttonsArray" label="{productsRepeater.currentItem.name}"/>
</mx:Repeater>
</mx:Panel>
</mx:Application>
[/codes]
【例3】:
MXML如下:
[codes=xml]<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" width="320" height="220">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.controls.RadioButton;
private function traceHandler(event:MouseEvent):void{
var numButtons:uint=buttonsArray.length;
var message:String="The repeater has "+numButtons;
message+=" dynamically created children:/r";
for(var i:uint=0;i<numButtons;i++){
var currentItem:RadioButton=buttonsArray[i];
var currentItemData:Object=currentItem.data;
message+=currentItemData.name+":$"+currentItemData.price;
if (currentItemData.freeship)message+="(free shopping!)";
message+="/r";
}
Alert.show(message);
}
]]>
</mx:Script>
<mx:ArrayCollection id="productsAC">
<mx:Object name="Whirlygig" price="5" freeship="false"/>
<mx:Object name="Tilty Thingy" price="15" freeship="true"/>
<mx:Object name="Really Big Blocks" price="25" freeship="true"/>
</mx:ArrayCollection>
<mx:Panel title="Emulating for..in loops--And8.net" paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10" borderColor="#00ff00">
<mx:Repeater id="productsRepeater" dataProvider="{productsAC}">
<mx:RadioButton id="buttonsArray" label="{productsRepeater.currentItem.name}" data="{productsRepeater.currentItem}"/>
</mx:Repeater>
<mx:ControlBar>
<mx:Button click="traceHandler(event)" label="Trace Repeater's children"/>
</mx:ControlBar>
</mx:Panel>
</mx:Application>
[/codes]
【例1】:
Flash动画
MXML如下:
[codes=xml]<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" width="320" height="200">
<mx:Script>
<![CDATA[
[Bindable]
public var myArray:Array=[1,2,3,4];
]]>
</mx:Script>
<mx:Panel paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10" title="Repeater emulating a for loop--And8.net" borderColor="#00ff00">
<!--注意绝对定位和相对定位-->
<mx:Repeater id="myRepeater" dataProvider="{myArray}">
<mx:Label id="myLabel" text="This is NO.{myRepeater.currentIndex}"/>
</mx:Repeater>
</mx:Panel>
</mx:Application>
[/codes]
【例2】:
Flash动画
MXML如下:
[codes=xml]<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" width="320" height="200">
<mx:ArrayCollection id="productsAC">
<mx:Object name="Whirlygig" price="5" freeship="false"/>
<mx:Object name="Tilty Thingy" price="15" freeship="true"/>
<mx:Object name="Really Big Blocks" price="25" freeship="true"/>
</mx:ArrayCollection>
<mx:Panel title="Emulating for..in loops--And8.net" paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10" borderColor="#00ff00">
<mx:Repeater id="productsRepeater" dataProvider="{productsAC}">
<mx:RadioButton id="buttonsArray" label="{productsRepeater.currentItem.name}"/>
</mx:Repeater>
</mx:Panel>
</mx:Application>
[/codes]
【例3】:
Flash动画
MXML如下:
[codes=xml]<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" width="320" height="220">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.controls.RadioButton;
private function traceHandler(event:MouseEvent):void{
var numButtons:uint=buttonsArray.length;
var message:String="The repeater has "+numButtons;
message+=" dynamically created children:/r";
for(var i:uint=0;i<numButtons;i++){
var currentItem:RadioButton=buttonsArray[i];
var currentItemData:Object=currentItem.data;
message+=currentItemData.name+":$"+currentItemData.price;
if (currentItemData.freeship)message+="(free shopping!)";
message+="/r";
}
Alert.show(message);
}
]]>
</mx:Script>
<mx:ArrayCollection id="productsAC">
<mx:Object name="Whirlygig" price="5" freeship="false"/>
<mx:Object name="Tilty Thingy" price="15" freeship="true"/>
<mx:Object name="Really Big Blocks" price="25" freeship="true"/>
</mx:ArrayCollection>
<mx:Panel title="Emulating for..in loops--And8.net" paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10" borderColor="#00ff00">
<mx:Repeater id="productsRepeater" dataProvider="{productsAC}">
<mx:RadioButton id="buttonsArray" label="{productsRepeater.currentItem.name}" data="{productsRepeater.currentItem}"/>
</mx:Repeater>
<mx:ControlBar>
<mx:Button click="traceHandler(event)" label="Trace Repeater's children"/>
</mx:ControlBar>
</mx:Panel>
</mx:Application>
[/codes]