MXML - 单击按钮动态创建组合框

时间:2013-05-13 02:45:13

标签: flex dynamic combobox mxml

需要有关在Flex中动态创建组合框的帮助。如何在点击按钮时动态创建组合框。

提前致谢。

1 个答案:

答案 0 :(得分:2)

例如:

public function createComboBox_clickHandler(event:Event):void {
            var myComboBox:ComboBox = new ComboBox();
            var comboBoxDataProvider:ArrayCollection =new ArrayCollection([
                { name: "box1", value: "value1"},
                { name: "box2", value: "value2"},
                { name: "box3", value: "value3"},
                { name: "box4", value: "value4"}
            ]);

            myComboBox.x = 100;
            myComboBox.y = 100;
            myComboBox.dataProvider = comboBoxDataProvider;
            myComboBox.labelField = "name";
            myComboBox.addEventListener(ListEvent.CHANGE, myComboBox_ClickHandler);
            container.addElement(myComboBox);
        }

        public function myComboBox_ClickHandler(event:ListEvent):void{
            trace(event.currentTarget.selectedItem.value);
        }

用于点击的按钮(以及两者的容器)

<s:BorderContainer id="container" width="100%" height="100%">
    <s:Button id="createComboBoxButton" click="createComboBox_clickHandler(event)" label="Create a combobox dynamically"/>
</s:BorderContainer>