Reputation: 26513
I have ArrayCollection
of strings with field names.
I would like to access object properties dynamically.
var myObject:MyObjectType = new MyObjectType();
var fields:ArrayCollection = new ArrayCollection(["f1", "f2", "f3"] );
for (var index:int = 0; index < (event.result as ArrayCollection).length; index++ ) {
myObject.[fields[index].toString()] = event.result[index];
}
How could I do tat?
Upvotes: 0
Views: 67
Reputation: 27536
You should replace the line inside the for loop by the following:
myObject[fields[index].toString()] = event.result[index];
// ^
// Remove the dot
Also, note thatfields
contains strings, so you can remove the .toString()
part:
myObject[fields[index]] = event.result[index];
Upvotes: 1