运行效果
代码:
selectCities.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" backgroundColor="white"
3 fontSize="12" horizontalAlign="left">
4
5 <mx:Array id="cities">
6 <mx:String>北京</mx:String>
7 <mx:String>天津</mx:String>
8 <mx:String>上海</mx:String>
9 <mx:String>深圳</mx:String>
10 <mx:String>广州</mx:String>
11 </mx:Array>
12
13 <mx:Panel title="选择城市" width="300"
14 paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10">
15 <mx:Repeater id="cityRepeater" dataProvider="{cities}">
16 <mx:CheckBox id="city" label="{cityRepeater.currentItem}"/>
17 </mx:Repeater>
18 <mx:HRule width="100%"/>
19 <mx:Button label="显示结果" click="showResult(event)"/>
20 </mx:Panel>
21
22 <mx:Script>
23 <![CDATA[
24 import mx.controls.Alert;
25
26 //访问Repeater生成的组件
27 private function showResult(event: MouseEvent): void
28 {
29 var results:Array = [];
30 for (var i:uint = 0; i <cities.length; i++)
31 {
32 if ((city[i]).selected)
33 results.push(cities[i]);
34 }
35 Alert.show("您选择了:\n" + results.join("\n"));
36 }
37 ]]>
38 </mx:Script>
39
40 </mx:Application>
41
2 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" backgroundColor="white"
3 fontSize="12" horizontalAlign="left">
4
5 <mx:Array id="cities">
6 <mx:String>北京</mx:String>
7 <mx:String>天津</mx:String>
8 <mx:String>上海</mx:String>
9 <mx:String>深圳</mx:String>
10 <mx:String>广州</mx:String>
11 </mx:Array>
12
13 <mx:Panel title="选择城市" width="300"
14 paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10">
15 <mx:Repeater id="cityRepeater" dataProvider="{cities}">
16 <mx:CheckBox id="city" label="{cityRepeater.currentItem}"/>
17 </mx:Repeater>
18 <mx:HRule width="100%"/>
19 <mx:Button label="显示结果" click="showResult(event)"/>
20 </mx:Panel>
21
22 <mx:Script>
23 <![CDATA[
24 import mx.controls.Alert;
25
26 //访问Repeater生成的组件
27 private function showResult(event: MouseEvent): void
28 {
29 var results:Array = [];
30 for (var i:uint = 0; i <cities.length; i++)
31 {
32 if ((city[i]).selected)
33 results.push(cities[i]);
34 }
35 Alert.show("您选择了:\n" + results.join("\n"));
36 }
37 ]]>
38 </mx:Script>
39
40 </mx:Application>
41