Getting TextArea on the stage (getChild by ID,Name)
I´m trying to get the 7 TextAreas on the stage on FlashBuilder,all of them have the id as "Desc1","Desc2","Desc3"... and the names are the same "Desc1","Desc2","Desc3"..., but when i try to get it,i get a error of a null object...
for(var i:int = 0;i<7;i++)
{
tr开发者_高级运维ace((stage.getChildByName("Desc"+(i+1))as TextArea).x);
}
I searched the web and dont find either any method of "getChildByID"
Flex IDs don't work with getChildByName(). getChildByName() is designed to work with ids of nested elements in Adobe Flash CS.
An flex id is an explicit declaration of a class member with name which is equal to the id. Due to the lack of macro in the actionscript laguage you cannot automate the creation of such lists of controls.
You can manually create an Vector or an Array of the text areas and use it in other part of your code to automatically iterate over your TextAreas:
var text_areas:Vector.<TextArea> = new Vector.<TextArea>();
text_areas.push(Desc1, Desc2, Desc3);
// or you can do this
var text_areas2:Array = [];
text_areas["Desc1"] = Desc1;
text_areas["Desc2"] = Desc2;
text_areas["Desc3"] = Desc3;
// Now you can iterate over the text areas
for each (var a_text_area:TextArea in text_areas)
{
....
}
Or you can create a flex Array:
<fx:Array id="textAreas">
<s:TextArea id="textArea1"/>
<s:TextArea id="textArea2" x="397" y="0"/>
<s:TextArea id="textArea3" x="201" y="1"/>
</fx:Array>
精彩评论