<mx:Repeater id="rep" dataProvider="{headingData.component}">
<mx:HBox id="panel" label="{rep.currentItem.title}"
width="100%" height="100%">
</mx:HBox>
</mx:Repeater>
protected function creationCompleteHandler():void
{
//Alert.show("init2");
var components:Array = getComponentsFromXML(xml.component);
var i:int = 0;
var n:int = components.length;
for (i; i < n; i++)
{
panel.addChild(components[i] as DisplayObject);
}
}
当我没有将它放在转发器标签下时,组件是从XML创建的,但是如果我这样做,则组件不会被创建。
任何问题。
<components type="array">
<component type="mx.controls::ComboBox" title="Title One" description="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." width="230" height="220">
<link linkname="Option one"/>
<link linkname="Option Two"/>
</component>
<component type="mx.controls::RadioButton" title="Title Two" width="230" description="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.">
<link linkname="Option one"/>
<link linkname="Option Two"/>
</component>
<component type="mx.controls::RadioButton" title="Title Three" width="230" description="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.">
<link linkname="Option one"/>
</component>
<component type="mx.controls::CheckBox" title="Title Four" width="230" description="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." height="220">
<link linkname="Option one"/>
<link linkname="Option Two"/>
<link linkname="Option Three"/>
</component>
<component type="mx.controls::RadioButton" title="Title Five" width="230" description="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." height="220">
<link linkname="Option one"/>
<link linkname="Option Two"/>
<link linkname="Option Three"/>
</component>
</components>
答案 0 :(得分:1)
好的,问题是Repeater内部的id='panel'
与正常情况有点不同。因为可以重复这些组件,如果你可以设置id,那么对于所有这些组件都是相同的。这就是为什么名称(在你的情况下是panel
)实际上是一个数组(在这种情况下是一个HBox的数组)。
如果要将子项添加到第一个子项,则需要选择第一个数组元素 -
panel[0].addChild(components[i] as DisplayObject);
答案 1 :(得分:0)
你需要许多HBox或许多组件吗?通常,Repeater不用于嵌套的东西,例如你的例子。此外,您不应该设置Repeater的孩子的'id'属性。 如果你需要一个复杂的组件,你应该从HBox继承并将as3代码粘贴到它中。
可能你必须将Repeater 包装成 HBox。然后,您不应将您的项目添加到面板中。它们应该在Repeater的dataProvider中指定。