3 Replies Latest reply on Feb 27, 2009 2:28 AM by MrFork

    Array Collection

    MrFork Level 1
      Hello All, I'm trying to access the label fields in my Array collection (see below) Im not sure what you call these whether they are columns, label fields, data fields etc. But if you see the simple array collection below, i need to access the values "Catchment", "Tier", "Spend" etc

      public var myData:ArrayCollection = new ArrayCollection ([

      {Catchment: "Calidot", Tier:"Tier 1", Spend: 400003, Visits: 394, Cards:350, ATV:23, SPC:13, VPC:1.2, ATVIndex:0, SPCIndex:3, VPCIndex:2},


      The reason for this is so I can create a dynamic data grid using the loop below. Obviously instead of "Spend" in the loop below it needs to be data .labelField...

      Could anyone help?

      //Data Loop

      for (var i:int = 0; i<data.length; i++)
      trace (data
      var column:AdvancedDataGridColumn = new AdvancedDataGridColumn ();
      column.dataField = "Spend";
        • 1. Re: Array Collection
          flexstone Level 1
          You can use this method on Objects like ArrayCollections, Models, etc...

          For objects with one item.....

          for(var myLabel:String in myObject){
          trace("my label is ="+ myLabel)

          for Object with multiple items use

          for(var myLabel:String in myObject[0]){
          trace("my label is ="+ myLabel)

          to get only the parameters for the first item (record )
          • 2. Re: Array Collection
            MrFork Level 1
            This brings out the labels in a strange order that is not the sames order as the data.

            Why does it do this? Sounds very strange to me, its not even listed alphabetically.

            Anyone know how to bring out the labels in the same order as the data?
            • 3. Re: Array Collection
              MrFork Level 1
              This is the code I am using.

              for (var myLabel:String in myData[0])
              columnArray.addItem({label: myLabel});