4 Replies Latest reply on May 21, 2007 5:44 PM by HyderAlamgir

# assigning Flex variables

HI I was wondering if someone could possibly help me ???

basically (as an example)....... I have an array that I want to "flatten" and put into an object..... e.g. :

var count:int = -1;
var flatObj:Object = new Object;
for(var x:int=0; x<myArray.length; x++)
{
count++;
flatObj.valueA_1 = myArray[count].valueA;
flatObj.valueB_2 = myArray[count].valueB;
flatObj.valueC_3 = myArray[count].valueC;
flatObj.valueD_4 = myArray[count].valueD;
}

but within the loop, I want to set the number valuse (valueA_1) = to the count value
e.g.
valueA_(count) etc.....

flatObj.valueA_(count) = myArray[count].valueA;
flatObj.valueB_(count) = myArray[count].valueB;
flatObj.valueC_(count) = myArray[count].valueC;
flatObj.valueD_(count) = myArray[count].valueD;

which sohud be the same ......

I just need to know, how I can add the count value to the string / test valueX_......
I assune ut is something like: valueA_{count} or valueA_#count# etc..... but I cant work it out :(

thanks again,
Jon.
• ###### 1. Re: assigning Flex variables
Use "bracket notation":
[ "flatObj.valueA_" + count ] = myArray[count].valueA;

Tracy

• ###### 2. Re: assigning Flex variables
Incidentally, in this case you don't need the "count" variable. You can just use the "x" variable.
[ "flatObj.valueA_" + x] = myArray[x].valueA;

Tracy
• ###### 3. Re: assigning Flex variables
Thanks Tracy
• ###### 4. Re: assigning Flex variables
Can we declare components dynamically using the bracket notation?

e.g.:

for (i=0; i<10; i++)
{
var ["lbl"+i]: Label= new Label;
}

Didn't work for me... is there a way that can be done?