1

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++)
{
   trace((stage.getChildByName("Desc"+(i+1))as TextArea).x);
}

I searched the web and dont find either any method of "getChildByID"

Vinicius Albino
  • 743
  • 2
  • 8
  • 21
  • Trace out "stage.numChildren" -- how many items do you see? Odds are, your TextAreas are not direct children of your stage, but are nested within another object. getChildByName will not perform a deep search of all children underneath the stage. – meddlingwithfire Sep 22 '11 at 19:40

1 Answers1

0

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>
Dmitry Sapelnikov
  • 1,129
  • 8
  • 16