Can I call a function when building an array in Flex 3?
public function gridBuilder(myArray:Array):void {
var i:uint;
for (i=0; i<myArray.length; i++){
dGArray = [
{Name: myArray[i].name, Type: 'A:', Score: myArray[i].score, Rank: myArray[i].rank, Grade:(myFunction(myArray[i].rank, myArray[i].max_rank))},
{Name: myArray[i].name, Type: 'B:', Score: myArray[i].score, Rank: myArray[i].rank }
]
}
dgAC = new ArrayCollection(dGArray);
}
MyArray is the result of a remote call to the database. I then prepare the array to be used in a dataGrid. I also want to call a function that provides a grade. Unfortunately, my function appears to be called only once. Is it possible to call a function when you’re building an array? Please see the “Grade:” bit. What’s the problem? How do I solve this problem?
Thank you!
-Laxmidi
You stated that your function was only called once. Yet in your code you are only explicitly calling it once. I am having trouble seeing your issue. In ActionScript, you can create an Array of objects, where attribute values can come from return values of functions.
EDIT Change your code to do this:
The problem with your original code was that you kept resetting your
dGArrayon each iteration.