2014-02-16 62 views
0

我想添加一個按鈕,單擊時添加另一個文本字段。我使用Adobe Flash Builder來編寫應用程序,因此需要使用MXML或ActionScript。任何想法如何做到這一點?使用MXML或actionscript單擊按鈕添加文本字段

事件處理程序按鈕當前指向此代碼,但是在第一次添加文本框後,它停止並不再添加。如何在每次單擊按鈕時循環添加文本框?

<fx:Script> 

    <![CDATA[ 
     protected function tableID(event:MouseEvent):void 
     {    
      var name:TextInput = new TextInput; 
      addElement(name); 
      name.move(50, 200); 
     } 
    ]]> 
</fx:Script> 

MXML:

<s:Button id="addBtn" x="175" y="450" label="+" click="tableID(event)" /> 
+0

你怎麼知道,只是暫時就先點擊添加TextInput和不得在隨後的點擊?看看你的代碼,我的假設是,每次你點擊按鈕,文本框被添加,但是,它被添加到以前的文本輸入的頂部,所以你不能在視覺上看到它。你還可以發佈你的MXML的按鈕節點,事件掛鉤。 –

回答

0

只需使用文本字段布爾變量。爲文本字段設置可見的includeInLayout &變量。在單擊按鈕時,將布爾變量的條件設置爲true或false。我認爲這會幫助你。

0

你可以試試這個方法:

<fx:Script> 
    <![CDATA[ 
     import mx.controls.TextInput; 
     protected function bt_clickHandler(event:MouseEvent):void 
     { 
      // TODO Auto-generated method stub 
      var item:TextInput = new TextInput(); 
      item.width = 50; 
      _parent.addElement(item); 
     } 
    ]]> 
</fx:Script> 

<fx:Declarations> 
    <!-- Place non-visual elements (e.g., services, value objects) here --> 
</fx:Declarations> 
<mx:Tile id="_parent" width="100%" height="100%"> 
    <s:Button id="bt" label="+" click="bt_clickHandler(event)"/> 
</mx:Tile> 
相關問題