Suppose you have a class in which you have declared
public var foo:int;
public var bar:int;
and that in a method you have two arrays
var names:Array = [ foo, bar ];
var values:Array = [ 1, 2 ];
Then the code
var n:int = names.length;
for (var i:int = 0; i n; i++)
{
this[names[i]] = values[i];
}
will set foo to 1 and bar to 2. This works because you can access foo by name
as this[foo].
Does that help?
Gordon Smith
Adobe Flex SDK Team
From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf
Of postwick
Sent: Wednesday, July 22, 2009 8:17 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: variables name are in array
This is very dangerous, IMO. It opens you up for getting things misaligned
and then you have the wrong value in the wrong variable.
Why aren't you storing the variable name AND the value in the same array?
--- In flexcoders@yahoogroups.commailto:flexcoders%40yahoogroups.com,
markflex2007 markflex2...@... wrote:
Hi,
Do you have a idea if I want to assign values in for loop?I already have two
arrays(one is for variable names,other is for variable values)
I have many values to assign and I want to assign them in loop.otherwise I
have to repeat many same assign statements.
Do you have a idea how to do this.
Thanks
Mark