[flexcoders] Binding property of object in dataProvider

2009-03-01 Thread gwangdesign
I am trying to bind a property (label) in my data object so that the
changes on it can be propagated to all the views (The controls may
want to edit this property). Currently I am wrapping them as plain
objects in ArrayCollection and I got the following warning:

warning: unable to bind to property 'label' on class 'Object' (class
is not an IEventDispatcher)

Does the compiler suggest making the Object a subclass of
IEventDispatcher? How do I do it if so?

My code is as below. Thanks!

mx:ArrayCollection id=taskList
mx:Object label=Word/
mx:Object label=Media Player/
mx:Object label=Contacts/
mx:Object label=Apache Server/
mx:Object label=Dictionary/
mx:Object label=iTunes/
mx:Object label=Solitaire/
mx:Object label=Minesweeper/
mx:Object label=Safari/
mx:Object label=RSS Reader/
/mx:ArrayCollection
mx:VBox
mx:Repeater id=myRP dataProvider={taskList} 
recycleChildren=true
mx:Button horizontalCenter=0
label={String(myRP.currentItem.label)}
click=button_ClickHandler(event);/
/mx:Repeater
/mx:VBox 



Re: [flexcoders] Binding property of object in dataProvider

2009-03-01 Thread Garth Somerville
If the point of your question is that you are starting with anonymous objects, 
then wrapping each item with a mx.utils.ObjectProxy will do what you want by 
making each property of the proxied object bindable.

The other alternative is not to use an anonymous object, but to create a 
concrete class for the tasks:

class Task {
  [Bindable]  public var label:String;
}

Ultimately this way is better for several reasons. (Note that as shown the mxml 
compiler will have to rewrite the class to implement IEventDispatcher)