Getting column names from arrayCollection

I wish to loop over an array collection and access all the elements (columns)

so the arrayCollection looks like

[1].columnOne
[1].columnTwo
[1].columnThree
[2].columnOne
[2].columnTwo
[2].columnThree

I need to loop over the rows and columns, but dont know the column names, any ideas.
LVL 18
PluckaAsked:
Who is Participating?
 
Jones911Connect With a Mentor Commented:
Try this:

It worked in AS2 and it wont work for bindable properties but it works for simple objects.

for (var key:String in object)
{
    data = object[key] ;
}

where object is your arraycollection item ie ac[0]
0
 
PluckaAuthor Commented:
Cool, I tried that but must have had something wrong.
0
 
papalphaCommented:
I'm a novice at Flex, ActionScript, and object oriented programming in general.  I'm trying to have a multi-dimension array (arrayCollection) (2 dimension) and want to access the column data using the first dimension (row pointer) (which is a string) as variable to point to the other  columns in the array.  I currently have:
private function getArrayDataValue(currentArray:ArrayCollection,fieldLabel:String):String {
var key:String = fieldLabel;
var displayValue:String = currentArray[key].data;
return displayValue;
}
I am getting the following error on execution:
Error: Unknown Property: 'freightTerms'.
      at mx.collections::ListCollectionView/http://www.adobe.com/2006/actionscript/flash/proxy::getProperty()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:694]
      at com.olt.transportation.update::UpdateFullView/getArrayDataValue()[C:\adobeFlexTraining\_workspace\FlexBuilder\src\com\olt\transportation\update\UpdateFullView.mxml:55]
      at <anonymous>()[C:\adobeFlexTraining\_workspace\FlexBuilder\src\com\olt\transportation\update\UpdateFullView.mxml:70]

The code calling the function is:
<mx:Label id="freightTerms" text="{getArrayDataValue(updateTR,'freightTerms')}"/>

Any reasonable suggestion will be greatly appreciated.
0
 
Jones911Commented:
An arrayCollection is not really a multidimetional array.  Its an array of Objects.

Also to access arrayCollection elements you must use

myArrayColelction.getItemAt(position);

you cant do myArrayColelction[1]
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.