如何访问数组元素

时间:2010-10-27 05:45:11

标签: flex actionscript-3 mxml

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

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

这里我如何以字符串或任何东西的形式访问文本输入数组的第一个,第二个以进一步继续

3 个答案:

答案 0 :(得分:1)

我不确定我是否理解您的问题是什么,但您没有设置文本输入的值:

我更喜欢以下方式:

//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);
}

您可以使用textInputs[0].text

来访问这些值
if(textInput != null){
  for(var i:Number = 0; i < textInputs.length; i++)
    trace(textInputs[i].text);
}

答案 1 :(得分:0)

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

如果您的精灵在索引0和&amp ;;处包含除TextInput之外的其他内容。 1你将得到空引用异常。

答案 2 :(得分:0)

Set chkbx = ActiveSheet.CheckBoxes.Add(t.Left, t.Top, 50, 0)
With chkbx
    .Name = "CheckBox_" & x
    .Caption = ""
End With