如何引用在運行時添加的子元素?Actionscript對子元素的引用
示例代碼:
for(var i:Number=1; i<=5;i++){
var mygroup:HGroup = new HGroup();
var mybutton:Button = new Button();
mybutton.label = "Browse Directory";
mybutton.addEventListener(MouseEvent.CLICK,browsedirectory);
var dirlbl:Label = new Label();
dirlbl.text = "C:/some directory/";
dirlbl.id = "path"+i;
mygroup.addElement(mybutton);
mygroup.addElement(dirlbl);
mygroup.id = "group"+i;
mainGroup.addElement(mygroup);
}
public function updatepath():void
{
this["path1"].text = "new path";
}
當我試圖通過調用this["path1"].text = "new path";
更改標籤的目錄路徑,並運行到錯誤
Error #1069: Property path1 not found and there is no default value.
我怎麼可以參考這些子元素?
謝謝。
「this」在您的代碼中是指什麼? –
'這'來自根。 – user1995781
檢查這些鏈接[link1](http://www.daveoncode.com/2009/05/20/objectcollector-accessing-dynamic-generated-flex-objects-by-id/)[link2](http:// www .jumpingbean.co.za/blogs/mark/flex_reference_components_dynamic_runtime_creation) –