0

I have an ArrayCollection with values predefined. I want to assign a new value to items in the arrayCollection but can not figure out how. Basically I want to do something like this: acGuages.itemUpdated(0).thevalue = 90; (Changing the value from 25 to 90). Thanks.

    private var arrayGuages:Array=[
        {thevalue:"25",height:"115"},
        {thevalue:"45",height:"115"},
        {thevalue:"15",height:"115"},
        {thevalue:"95",height:"115"},
        ];

    [Bindable] 
    public var acGuages:ArrayCollection=new ArrayCollection(arrayGuages);

    acGuages.itemUpdated(0).thevalue = 90;
leif
  • 195
  • 1
  • 7
  • 17

1 Answers1

2

ArrayCollection supports random access to its elements, just like Array. In other words, your line:

acGuages.itemUpdated(0).thevalue = 90;

Can be rewritten as:

acGuages[0].thevalue = 90;

And it should all work as expected.

Dan
  • 836
  • 1
  • 5
  • 11
  • Great, thanks. I also updated it so it was being set in an initialize function. public function int():void { acGuages[0].thevalue = 90; acGuages.refresh(); } – leif Nov 27 '09 at 18:47
  • 1
    Glad it worked :) FYI, you probably don't need the call to refresh() in your init function. If memory serves me correctly, refresh() is only needed if you're applying a filter or a sort. – Dan Nov 27 '09 at 18:58