Flex 使用Repeater组件

Repeater组件在重复制作一些简单用户界面组件上是很有用的。比如单选按钮。Repeater组件还可以用来效仿For循环。和asp.net里的Repeater挺像的。
【例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]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值