Apache flex 运行时的Flex组件 受保护的函数creationCompleteHandler():void { //警报显示(“初始2”); var-components:Array=getComponentsFromXML(xml.component); 变量i:int=0; var n:int=组件长度; 对于(i;i

Apache flex 运行时的Flex组件 受保护的函数creationCompleteHandler():void { //警报显示(“初始2”); var-components:Array=getComponentsFromXML(xml.component); 变量i:int=0; var n:int=组件长度; 对于(i;i,apache-flex,Apache Flex,当我不把它放在repeater标记下时,组件是从XML创建的,但是如果我这样做了,那么组件就不会被创建 任何问题 <mx:Repeater id="rep" dataProvider="{headingData.component}"> <mx:HBox id="panel" label="{rep.currentItem.title}" width="100%" height="100%"> </mx:HBox> &

当我不把它放在repeater标记下时,组件是从XML创建的,但是如果我这样做了,那么组件就不会被创建

任何问题

<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);
                }
            }

您需要许多HBox还是其中的许多组件?通常,中继器不用于嵌套的对象,如您的示例中所示。此外,您不应该设置中继器的孩子的“id”属性。 如果您需要一个复杂的组件,您应该从HBox继承并将as3代码粘贴到其中


可能,您必须将中继器包装到HBox中。那么你就不应该把你的项目添加到面板中。它们应该在中继器的数据提供程序中指定。

好的,问题是中继器内部的
id='panel'
工作原理与正常情况稍有不同。因为这些组件可以重复,如果您只需设置id,那么所有组件的id都是相同的。这就是为什么名称(在您的示例中是
面板
)实际上是一个数组(在本例中是一个HBox数组)

如果要将子元素添加到第一个元素,则需要选择第一个数组元素-

<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>

为什么HBox在中继器中?你想拥有更多的HBox吗?我如何在不指定任何ID或其他参数的情况下动态放置它?如果你能解释它应该做什么,可能会更容易帮助你。如果替换panel.addChild(组件[i]作为DisplayObject);使用我粘贴的行,它会将这些子项添加到第一个HBox中。
 panel[0].addChild(components[i] as DisplayObject);