2013-04-02 47 views
0

我的代碼簡介:在滾動條內有一個Vgroup,因爲用戶要添加一些對象。Flex獲取Hgroup的第一個對象

每次用戶點擊按鈕時,它都會添加到內部有3個對象的Vgroup和Hgroup中(請參閱agregar_clickhandler)。這3個對象是一個textInput,數字步進器和一個刪除圖標。

我想要做的是每次用戶編輯它時,提取每個Hgroup中textinput和numeric步進器中的信息。

例如,當我必須刪除一個Hgroup時,我使用了Eliminar函數,該函數運行良好。我嘗試做類似的事情來獲取textInput中的文本,但沒有任何工作。

我在做什麼是我添加一個事件監聽器到TextInput,所以當用戶鍵入的東西,我可以提取該信息。

我很感激幫助。

<s:Button id="agregar" x="36" y="533" label="Agregar mas mensajes " fontSize="20" 
    click="agregar_clickHandler(event)"/> 

<s:Scroller x="36" y="99" width="554" height="400"> 
    <s:VGroup width="100%" height="100%" id="scroller"> 
    </s:VGroup> 
</s:Scroller> 

     protected function agregar_clickHandler(event:MouseEvent):void 
     { 
      // TODO Auto-generated method stub 
      var group:HGroup = new HGroup(); 
      group.width = 552; 
      group.height = 65; 

      var input:TextInput = new TextInput(); 
      input.width = 360; 
      input.height = 49; 
      input.addEventListener(TextOperationEvent.CHANGE, actualizar); 

      var num:NumericStepper = new NumericStepper(); 
      num.width = 107; 
      num.height = 49; 
      num.maximum = 100; 

      var del:Button = new Button(); 
      del.width = 70; 
      del.height = 49; 
      del.label = "delete"; 
      del.setStyle("icon", deleteicon); 
      del.addEventListener(MouseEvent.CLICK, eliminar); 

      group.addElement(input); 
      group.addElement(num); 
      group.addElement(del); 

      scroller.addElement(group); 
     } 

protected function eliminar(event:MouseEvent):void 
     { 
      scroller.removeElement(HGroup(Button(event.currentTarget).parent)); 
     } 

protected function actualizar(event:TextOperationEvent):void 
     { 

      var obj:Object = scroller.getElementIndex(HGroup(TextInput(event.currentTarget).parent)); 

     } 
+0

你應該使用DATAGROUP或List組件添加並通過itemRenderer的動態刪除視圖。看看這個答案的一個非常類似的問題:http://stackoverflow.com/questions/14870771/how-to-select-an-object-in-a-flex-hgroup/14911747 – RIAstar

回答

0

試試這個:

protected function actualizar(event:TextOperationEvent):void 
{ 
    var currentHGroup:HGroup = HGroup(TextInput(event.currentTarget).parent); 

    var currentText:String = (currentHGroup.getElementAt(0) as TextInput).text; 
    var currentNumber:int = (currentHGroup.getElementAt(1) as NumericStepper).value; 
}