2 Replies Latest reply on Oct 1, 2010 8:14 AM by SiHoop

    Labeling records in an array or arrayCollection

    SiHoop Level 1

      Several of the Tour de Flex examples use an array in a way that is unfamiliar to me. For example: var array:Array= [{Profit: 2000 }, {Profit: 2400 } ];


      I want to put my data into the array as follows:  var array1:Array= [2000,2400];

      but I still want to be able to access the 'Profit' property when I use an ArrayCollection as in the example below.


      So, I have 2 questions:

      First, what is the name given to populating an array as:  var array:Array= [{Profit: 2000 }, {Profit: 2400 } ];


      Second, how do I label my data with 'Profit' when I add it to an array or an ArrayCollection?


      Thanks for your time.



      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  creationComplete="init()" >
          import mx.collections.ArrayCollection;
          private function init():void{
              var array:Array= [{Profit: 2000 }, {Profit: 2400 } ];
               var ac0:ArrayCollection = new ArrayCollection(array);
               var array1:Array= [2000,2400];
               var ac1:ArrayCollection = new ArrayCollection(array1);
          <mx:Panel >
              <mx:AreaChart id="areachart" color="0x323232" height="100">                   
                      <mx:AreaSeries yField="Profit"  />
          <mx:Panel >
              <mx:AreaChart id="areachart1" color="0x323232" height="100">                   
                      <mx:AreaSeries yField="Profit"  />

        • 1. Re: Labeling records in an array or arrayCollection
          BhaskerChari Level 4

          Hi SiHoop,


          You need to defenitely label it when you are assiging the data to the Array itself.


          var array:Array= [{Profit: 2000 }, {Profit: 2400 } ];


          The above one is equivalent to creating an object and pushing the data into array.


          So you can use the above statement as ...below


          var array:Array= new Array();

          var obj:Object = new Object();


          obj.Profit = 2000;


          obj:Object = new Object();

          obj.Profit = 2400;


          Actually {Profit: 2000 } represnts an Object ...in which Profit is the label(property of Object) for the value.


          var array:Array= [{Profit: 2000 }, {Profit: 2400 } ]; is the simplest way of initializing the Array. You need to label it before only then only you could access it with the label.




          • 2. Re: Labeling records in an array or arrayCollection
            SiHoop Level 1

            Great answer-- thank you!