2010-10-27 5 views
0
var count:uint = 0; 
var textInputs:Array /* of TextInputs */ = []; 
for(var i:String in columnsData){ 
    textInputs[count] = new TextInput(); 

    addChild(textInputs[count]); 
    count++; 
} 

ici comment puis-je accéder à la première, deuxième tableau de textinputs sous forme de chaîne ou quelque chose à plus procéderComment accéder aux éléments du tableau

+0

ce qui ne va pas avec textInputs [0] .text et textInputs [1] .tex t? – PatrickS

Répondre

0
(getChildAt(0) as TextInput).text //first 
(getChildAt(1) as TextInput).text //second 

Si l'image-objet contient autre chose que TextInput aux index 0 & 1 vous obtiendrez une exception de référence nulle.

+0

ce getChildAt relève-t-il ..? – mani

+0

fonction publique ContinclickHandler(): void { if (continu.label == "Continuer") { Alert.show ("Inside"); // premier Alert.show (fieldInputs [0] .text.toString()); Donc ici j'accède fieldInputs [0] dans la fonction séparée mais je ne peux pas montrer le script flex mais le message intérieur dans Alert vient pourquoi pas fieldinputs – mani

1

Je ne sais pas si je comprends bien votre question est, mais vous n'êtes pas le réglage de la valeur pour les entrées de texte:

Je le préfère la manière suivante:

//make the array an instance variable instead of local var 
//so that it can be accessed from other functions if required. 
public var textInputs:Array = []; 

for(var str:String in columnsData) 
{ 
    var ti:TextInput = new TextInput(); 
    ti.text = str; 
    addChild(ti); 
    textInputs.push(ti); 
} 

Vous pouvez accéder à la valeurs à l'aide textInputs[0].text etc.

if(textInput != null){ 
    for(var i:Number = 0; i < textInputs.length; i++) 
    trace(textInputs[i].text); 
} 
0
<?xml version="1.0"?> 
<!-- dpcontrols\UseIList.mxml --> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    initialize="initData();"> 
    <s:layout> 
     <s:VerticalLayout/> 
    </s:layout> 

    <fx:Script> 
     <![CDATA[ 
      import mx.collections.*; 

      // The data provider is an Array of Strings 
      public var myArray:Array = ["AZ", "MA", "MZ", "MN", "MO", "MS"]; 
      // Declare an ArrayList that represents the Array. 
      [Bindable] 
      public var myAL:ArrayList; 

      //Initialize the ArrayList. 
      public function initData():void { 
       myAL = new ArrayList(myArray); 
      } 

      // The function to change the collection, and therefore 
      // the Array. 
      public function changeCollection():void { 
       // Get the original collection length. 
       var oldLength:int=myAL.length; 

       // Remove the invalid first item, AZ. 
       var removedItem:String=String(myAL.removeItemAt(0)); 
       // Add ME as the second item. (ILists used 0-based indexing.) 
       myAL.addItemAt("ME", 1); 
       // Add MT at the end of the Array and collection. 
       myAL.addItem("MT"); 
       // Change the third item from MZ to MI. 
       myAL.setItemAt("MI", 2); 
       // Get the updated collection length. 
       var newLength:int=myAL.length; 
       // Get the index of the item with the value ME. 
       var addedItemIndex:int=myAL.getItemIndex("ME"); 
       // Get the fifth item in the collection. 
       var index4Item:String=String(myAL.getItemAt(4)); 

       // Display the information in the TextArea control. 
       ta1.text="Start Length: " + oldLength + ". New Length: " + 
        newLength; 
       ta1.text+=".\nRemoved " + removedItem; 
       ta1.text+=".\nAdded ME at index " + addedItemIndex; 
       ta1.text+=".\nThe item at index 4 is " + index4Item + "."; 
       // Show that the base Array has been changed. 
       ta1.text+="\nThe base Array is: " + myArray.join(); 
      } 
     ]]> 
    </fx:Script> 

    <s:ComboBox id="myCB" dataProvider="{myAL}"/> 
    <s:TextArea id="ta1" height="75" width="300"/> 
    <s:Button label="rearrange list" click="changeCollection();"/> 
</s:Application> 
Questions connexes