? ? ?mx组件中的Repeater类似与sprak中的DataGroup,可以根据数据源循环一些组件,例如:一组RadionButton。
?
? ? ?网上的很多例子都是用mxml写的,本文将主要介绍用as来编写Repeater。
?
? ? ?1 先定义好Repeater所在的容器,例如下面代码
? ? ? ?? <mx:Tile direction="horizontal" borderStyle="none" id="tile"
horizontalGap="0" verticalGap="0" paddingLeft="0" paddingTop="0" paddingBottom="0" paddingRight="0"> <mx:Repeater id="rp" > </mx:Repeater> </mx:Tile>
?
2 ?编写Repeater的childDescriptors?
?
? ??var descriptorProps:Object = {};
descriptorProps.type = RadioButton;
descriptorProps.document = this;
descriptorProps.propertiesFactory = radioPropFac;
descriptorProps.events = {change:"radioButton_change"};
var radioDescriptor:UIComponentDescriptor = new UIComponentDescriptor(descriptorProps);
rp.dataProvider = ac2;
rp.childDescriptors = [radioDescriptor];
rp.initializeRepeater(tile, true);
?
? 3 ?编写RadioButton的属性?
?
? ??private function radioPropFac():Object {
var obj:Object = {};
obj.label = rp.currentItem.name;
obj.group = group;
obj.maxWidth=120;
return obj;
}
?
?
?
?
?
?