Yes, that is what you must do when instantiating components manually.
An option to the Array is an "associative array". An associative array
is essentially just an Object, and you choose a descriptive name for the
property name, and assign a reference to your created component to the
property value.
var private var _oDynVars:Object = new Object;
for(var o:uint = 0; o < NumText; o++)
{
....
curItem = "sTextInput"+ o.toString();
oDynVars[curItem] = new TextInput();
....
}
You can now reference those TextInputs like this:
var tiCurrent:TextInput = oDynVars[sTextInput1"];
Of course, this would be more useful if you had a descriptive name you
could use, like "FirstName", "LastName", etc.
Tracy
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of jer_ela
Sent: Monday, March 24, 2008 8:42 AM
To: [email protected]
Subject: [flexcoders] Re: create looping component programmatically
create an array property textInputs to hold the references to the
dynamically create TextInputs. Then use code like this:
for(var o:uint = 0; o < NumText; o++)
{
textInputs[o] = new TextInput();
textInputs[o].width=356,
textInputs[o].text="Text Goes Here";
someComponent.addChild(textInputs[o]);
}
You can then refer to a particular textInput as textInputs[n]
You need to do the addChild to actually add the TextInputs to the user
interface.
--- In [email protected] <mailto:flexcoders%40yahoogroups.com>
, Ary <[EMAIL PROTECTED]> wrote:
>
> hi guys :)
>
> i know its possible, but i just dont know how ...
> i want to make several text input programmatically,
> number of text input created is based on certain
> variable, and has to be to be unique, need to access
> the component later on.
>
> here is a chunk of the code (get
>
> for(var o:uint = 0; o < NumText; o++)
> {
> curItem = "sTextInput"+ o.toString();
> var this[curItem]:sLabelTextInput = new
> sLabelTextInput();
> sTextInput.id=("txtTemplate"+(o)),
> sTextInput.width=356, sTextInput.text="Text Goes
> Here";
> //sTextInput.setStyle('fontFamily',
> 'Verdana'), sTextInput.setStyle('fontSize', 11);
>
>
> }
>
>
>
__________________________________________________________
> Looking for last minute shopping deals?
> Find them fast with Yahoo! Search.
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
<http://tools.search.yahoo.com/newsearch/category.php?category=shopping>
>