我是Adobe AIR的新手,这就是我正在做的事情(请注意我是通过AS3代码执行此操作的:
将VGroup添加到Canvas控件。
var vIncomeHeader:VGroup = new VGroup();
vIncomeHeader.width = 1326;
vIncomeHeader.height = 29;
vIncomeHeader.id = "vIncomeHeader";
canvasIncome.addChild(vIncomeHeader);
创建HGroup并将其添加到第一步中创建的VGroup。
创建5个TextInput并将其添加到HGroup。第一个文本框是可编辑的,其余部分不可编辑。
var hfIncomeHeader:HGroup = new HGroup();
var txt:TextInput = new TextInput();
vIncomeHeader.addElement(hfIncomeHeader);
var lp:int =0;
var lp-inner:int =0;
for (lp=0; lp<10; lp++)
{
hfIncomeHeader = new HGroup();
hfIncomeHeader.width = 1326;
hfIncomeHeader.height = 29;
//Amount
txt = new TextInput();
txt.id = "txtAmount_" + lp;
txt.width = 120;
txt.height = 22;
txt.restrict = "0-9.\\";
txt.addEventListener(Event.CHANGE, txtChangeIncomeAmount);
hfIncomeHeader.addElement(txt);
for (lp-inner=0; lp-inner<4; lp-inner++)
{
//Income Type
txt = new TextInput();
txt.id = "txt_" + lp + "_" + lp-inner;
txt.width = 120;
txt.height = 22;
hfIncomeHeader.addElement(txt);
}
}
//txtChangeIncomeAmount
protected function txtChangeIncomeAmount(event:Object):void
{
// HOW TO Do IT
}
[第二步和第三步是for循环的一部分,从0到10]
现在,我想要做的是在第一个文本框中写入数字,并自动将相同的数字填充到该HGroup的其他4个文本框中。
答案 0 :(得分:2)
您可以为TextInput设置名称,然后按名称获取它们。这样的事情:
...
txt.name = "txt_" + lp-inner;
...
protected function txtChangeIncomeAmount(event:Event):void
{
var txt:TextInput;
for (var i:uint = 0; i < 4; i++)
{
txt = hfIncomeHeader.getChildByName("txt_" + i) as TextInput;
txt.text = (event.currentTarget as TextInput).text;
}
}