Getting column names from arrayCollection

Posted on 2008-11-06
Last Modified: 2013-11-11
I wish to loop over an array collection and access all the elements (columns)

so the arrayCollection looks like


I need to loop over the rows and columns, but dont know the column names, any ideas.
Question by:Plucka
    LVL 19

    Accepted Solution

    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]
    LVL 18

    Author Closing Comment

    Cool, I tried that but must have had something wrong.

    Expert Comment

    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/[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\]
          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.
    LVL 19

    Expert Comment

    An arrayCollection is not really a multidimetional array.  Its an array of Objects.

    Also to access arrayCollection elements you must use


    you cant do myArrayColelction[1]

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
    The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
    The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
    This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now