【问题标题】:Flex components at runtime运行时的 Flex 组件
【发布时间】:2010-02-18 12:00:15
【问题描述】:
<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>

【问题讨论】:

    标签: apache-flex


    【解决方案1】:

    好的,问题是中继器内的id='panel' 的工作方式与正常情况有些不同。因为这些组件可以重复,所以如果您可以设置 id,那么所有这些组件都是相同的。这就是为什么名称(在您的情况下为panel)实际上是一个数组(在这种情况下是一个 HBoxes 数组)。

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

     panel[0].addChild(components[i] as DisplayObject);
    

    【讨论】:

    • 如何在不指定任何 ID 或其他参数的情况下动态放置它
    • 如果您真正解释应该做什么,可能会更容易帮助您。如果您更换 panel.addChild(components[i] as DisplayObject);使用我粘贴的行,它会将这些孩子添加到第一个 HBox。
    【解决方案2】:

    你需要很多 HBox 还是里面的很多组件?通常,Repeater 不用于您的示例中的嵌套事物。此外,您不应该设置中继器孩子的 'id' 属性。 如果您需要一个复杂的组件,您应该从 HBox 继承并将该 as3 代码粘贴到其中。

    可能,您必须将Repeater 包装到 HBox。那么你不应该将你的项目添加到面板中。它们应该在Repeater的dataProvider中指定。

    【讨论】:

    • 为什么 HBox 在中继器中?你想拥有更多的 HBox 吗?
    猜你喜欢
    • 2012-04-29
    • 2011-06-07
    • 2010-11-05
    • 2010-10-11
    • 1970-01-01
    • 2010-09-27
    • 1970-01-01
    • 1970-01-01
    • 2012-05-16
    相关资源
    最近更新 更多