Search code examples
apache-flexmobileitemrendererarraycollectionbindable

Listen to bindable property in bindable Arraycollection


I've got a bindable model class (lets call it myModel) with two properties, label and value. The value gets updated frequently, so it is marked as bindable. Works fine so far, the data is updated and the standard property change event is dispatched.

Now I have to make an ArrayCollection from the object instances of this model to use it as a data provider in a data group. The data gets then passed to a custom itemRenderer in which I access the myModel properties via data.label and data.value.

The only problem I've got now is that the myModel value property doesn't change any more (I suppose because I stored the objects in the ArrayCollection).

The ArrayCollection is marked bindable as well btw, because new object instances of myModel can be added during runtime.

Is there any way to make this work? Any help regarding this would be much appreciated!

Edit: I almost forgot, the value object in the myModel class is updated by another bindable class. Yes, I know that's bonkers but that's why I'm here, to get some input on a simpler (and in fact working) way to solve this problem.

2nd edit: Allright guys, a little bit of code to illustrate the issue;

Lets start with the first bindable class;

[Bindable]
public class FirstClass
{
   public var name:String;
   public var firstValue:Number;
   public var secondValue:Number;
   public var thirdValue:Number;

   public function FirstClass()
   { }
 }

The values (first to third) get updated by a controller class. So far so good. Now to the second model class (for matters of consistency, lets keep the MyClass name)

[Bindable]
public class MyClass
{
   public var label:String;
   public var value:Number;

   public function FirstClass()
   { }
 }

These are the two model classes. Background behind this is that I need a String value (a label) for each property of an instance of FirstClass. I'd like to make this simpler, so I'm really not settled on this "solution" cough ;).

Anyhow, we've got the two models, now to my .mxml class;

[Bindable] private var firstClassInstance:FirstClass;

I create a new ArrayCollection and add objects like this; myArrayCollection.addItem(new MyClass("This is a label", firstClassInstance.firstValue));

And again, the DataGroup uses this ArrayCollection as a data provider.

As we already established (thank you @Windowns), the ArrayCollection looks only for objects being added or removed, not property changes of these objects.


Solution

  • I took Amy's advice and researched a little further on the itemUpdated method. Turns out, the solution was right there.

    See here: http://flex4examples.wordpress.com/2009/08/28/1st/

    I applied this methodology (with little variations) to my code and it works quite good. Performance on the iPad2 is good and so is the memory usage of my component.

    Let's hope that Amy is fine with this solution as well. Fingers crossed. ;)