![](/img/trans.png)
[英]Problem getting in Flex Effects: Migration from Flex3 to Flex4
[英]Getting values from dynamic controls in flex3
我是 Flex 3 和 ActionScript 的新手。 我想知道如何通过它们的 id 获取动态文本框的值。
for (var countz:int = 0; countz < questionCount; countz++)
{
hboxtextboxz = new HBox();
txt = new TextInput();
txt.id = countz + "";
hboxtextboxz.addChild(txt);
}
有谁知道我如何从我用 for 循环创建的动态文本框中获取值?
要动态获取 Container 的所有子项,请使用getChildren()
方法。 它将返回一个UIComponent
数组,如果它们是TextInput
实例,则将它们转换并使用text
属性获取值。
从 HBoxes 内的容器中获取所有文本框的示例代码。
var children:ArrayCollection = textBoxContainer.getChildren();
for(var i:int = 0; i < children.length; i++)
{
var hbox:HBox = HBox(children[i]);
var textBox:TextInput = TextInput( hbox.getChildAt(0));
if(textBox != null)
{
trace(textBox.text);
}
}
上面的代码提供您的 UI 结构如下:
<VBox id="textBoxContainer">
<HBox>
<TextInput/>
</HBox>
....
</VBox>
值是指框内的文本吗?
如果你想在你的 for 循环中访问它,只需使用变量名:
txt.文本
否则,如果您在 MXML 中创建文本框,您可以设置其 id 参数并使用该参数访问它: (text fields id).text
应该为您提供已插入该框中的文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.