2 Replies Latest reply on Nov 7, 2006 6:06 AM by mattMullally

    help on setItem

    mattMullally
      Howdy all,

      I am having a problem setting a value in a ArrayCollection;

      I have an arraycollection that has two columns valueLabel and valueScore with data in it.
      The data is then bound to the datagrid, works great.

      In another function I need to set the Item of the valueScore at a certain index with a value. I cant seem to figure it out.
      ac is the name of my collection. When I run the below line of script, it changes values for all the columns. I cant figure out the syntax for telling it a certain column in the arraycollection. Help please.

      ac.setItemAt(Math.round(event.value),0); // this sets all columns

      I need something like:
      ac.["valueScore"].setItemAt(Math.round(event.value),0); //needless to say this throw exception everywhere

        • 1. Re: help on setItem
          chris.huston.t10 Level 3
          Here's an example that might help:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init_ac()">
          <mx:Script><![CDATA[
          import mx.collections.ArrayCollection;

          [Bindable]
          public var ac:ArrayCollection;

          private function init_ac():void {
          ac = new ArrayCollection();
          ac.addItem({valueLabel:"label 1", valueScore:5});
          ac.addItem({valueLabel:"label 2", valueScore:10});
          }
          private function increment_score(ac_index:uint):void {
          var my_obj:Object = ac[ac_index];
          my_obj.valueScore++;
          ac.setItemAt(my_obj, ac_index);
          }
          ]]></mx:Script>

          <mx:DataGrid x="109" y="161" dataProvider="{ac}">
          <mx:columns>
          <mx:DataGridColumn headerText="Labels" dataField="valueLabel"/>
          <mx:DataGridColumn headerText="Scores" dataField="valueScore"/>
          </mx:columns>
          </mx:DataGrid>
          <mx:Button x="123" y="98" label="Increment Label 1" click="increment_score(0)"/>
          <mx:Button x="261" y="98" label="Increment Label 2" click="increment_score(1)"/>

          </mx:Application>

          Vygo
          • 2. Re: help on setItem
            mattMullally Level 1
            Thanks!