Skip navigation
Gug88
Currently Being Moderated

Array Manipulation

Feb 18, 2013 8:03 AM

Hello i am abit stuck to how to access the data into an array

 

  • I have used the following code 

 

public function Adddata():void{

  Testing.addItem({ProcessName:ProcessNameInput.text ,

                            Cost:CostInput.text,

                            ProcessTime:ProTimeIP.text,

                                  

 

  });

 

  • To add data in the relevent array collecition

 

 

<s:ArrayCollection id="Testing">

 

</s:ArrayCollection>

 

  • And have called it into the data grid to be able to see it visually

 

<mx:DataGrid id="ProssGrid" includeIn="ProcessesView"                                         dataProvider="{Testing}"

                                        >

                    <mx:columns>

                              <mx:DataGridColumn dataField="ProcessName" headerText="Process Name"/>

                              <mx:DataGridColumn dataField="Cost" headerText="Cost"/>

                              <mx:DataGridColumn dataField="ProcessTime" headerText="Process Time"/>

            

                    </mx:columns>

          </mx:DataGrid>

 

 

The question is that i need to manipulate the data such as to do cost*processTime , what code do i have to do to access the elements inorder to work with the values achieved ...

 

Thanks a million

 

Thanks

 
Replies
  • Currently Being Moderated
    Feb 18, 2013 8:24 AM   in reply to Gug88

    It depends on where you want to access it.

     

    If you want a 4th column to display Cost * ProcessTime, then you could create an ItemRenderer/GridItemRenderer which takes the data from the column in order to get the values

     

    i.e.  In the GridItemRenderer

     

    override public function set data(value:Object):void {

         super.data = value;

         if(value != null) {

              itemRenderer_Label.text = Number(data["Cost"]  *  data[""] ).toString();

         }

    }

     

    Or, you could just add it when you populate late the array.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 18, 2013 9:46 AM   in reply to Gug88

    Then you should add it to the Array when you populate it and make sure you have a unique identifier for the row.  If "XXX" is the product name, when you do the insert, you need to add a column for the unique ID.

     

    I handle my ArrayCollections by creating an Object class then inserting each Object into an ArrayCollection.  I usually access my data from a webservice which provides the XML data to populate the ArrayCollection.  Once the ArrayCollection is populated, then I can simply access the row and then the object column to get the data that I need.

     

    i.e.

    Add each item to the Array Collection

    myArrayCollection.addItem(ProductObjectClass.addItem(ProcessName,Cost, ProcessTime));

     

    When you want to get the information then you can use  myArrayCollection.getItemAt(i) to put it back into an ProjectObjectClass and find the correct value within that object;  Where i would be the row.  If you click on the DataGrid, then you would have the rowIndex value to get that rows data with the unique id.  Then when you did an update, you could update based on uid.   Or, you could have inline editing on the DataGrid.

     

     

     

    public class ProjectObjectClass extends Object

    {

     

    public static function addItem(thisProcessName:String, thisCost:String, thisProcessTime:String):Object{

     

         var now:Date = new Date(); // create date time instance in order to use time stampe as unique id

     

         var poc:ProjectObjectClass = new ProjectObjectClass();

         poc.uid = now.valueOf();

         poc.processName = thisProcessName;

         poc.cost = new Number(thisCost);

         poc.processTime = new Number(thisProcessTime);

         poc.processTimeCost = poc.processTime * poc.cost;

     

         return poc

     

    }

     

    public function ProjectObjectClass()

    {

         super();

    }

     

      [Bindable]

      public var uid:Number  

      [Bindable]

      public var processName:String;

      [Bindable]

      public var cost:Number;

      [Bindable]

      public var processTime:Number;

      [Bindable]

      public var processTimeCost:Number;

    }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points