-1

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

提前致谢。

4

1 回答 1

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>
于 2013-05-13T10:07:17.390 回答