2013-05-13 43 views
-1

需要在Flex中動態創建組合框的幫助。如何在點擊按鈕時動態創建組合框。MXML - 點擊按鈕動態創建組合框

在此先感謝。

+1

能否請您提供您的代碼示例與其中一部分的給你細節一起麻煩? – 2013-05-13 03:07:55

+0

我是新來flex和mxml。試圖開發小應用程序。尋找一些例子。謝謝。 – user2376184 2013-05-13 03:13:03

回答

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>