views:

286

answers:

1

I feel like this should be a simple thing, but here I am asking the question after a good amount of frustration.

Ok I have a project I'm doing in Cairngorm in Flex 3. In one of the components I have a tile list that's bound to a VO in a Model Locator. I want to run a function once that VO contains some data that basically adds sums a certain value in that VO. I was at the Flex Jam in Ann Arbor and I thought James did this with getters & setters with his Cairngorm example.

Is this a simple thing? Does anyone have an example of how to do this? Is there an easier way?

Thanks ahead of time for any help/advice.

A: 

It sounds like what he did was add a getter/setter for the collection property in the VO which recalculates that summed value based on the contents of the new collection, i.e. This is a pretty standard approach and the code below is not difficult.

private _yourCollection:ArrayCollection;

public function set yourCollection( value:ArrayCollection ):void
{
    if ( _yourCollection != value)
    {
        _yourCollection = value;
        // calculate new sum
        var sum:Number = 0;
        for each ( var obj:SomeVOType in _yourCollection )
            sum += obj.valueToSum;
        sumProperty = sum;
    }
}
cliff.meyers