Hi,
when I explicitely use databing in my development, I often encounter the following issue :
I link an ArrayCollection with a view component, in order to provide the data to display, using the {} syntax in the skin mxml class.
In the .as skinnable component class, I define a getter/setter bindable methods which store data, set a changing flag to false and call the invalidateDisplayList() method. In the updateDisplayList() method, I iterate through the ArrayCollection and I add visual items to the component display list.
protected var _data:ArrayCollection;
protected var _dataChanged:Boolean;
[Bindable]
public function get data():ArrayCollection
{
return _data;
}
public function set data( p_value:ArrayCollection ):void
{
_data = p_value;
_dataChanged = true;
invalidateDisplayList();
}
override protected function updateDisplayList( p_unscaledWidth:Number, p_unscaledHeight:Number ):void
{
super.updateDisplayList( p_unscaledWidth, p_unscaledHeight );
if( _dataChanged )
{
// create and add items
}
}
This mechanism works fine.
But if I modify the original ArrayCollection using addItem() or removeItem() methods, which is supposed to be binded with the component, the setter is not called and nothing happens.
I have to explicitely call the setter method and re-create an ArrayCollection for the component to update the display list.
Is it the regular mechanism or do I miss something?
Thanks.
Vincent.
In your scenario, dataBinding is only watching for the instance of the ArrayCollection to change, it is not watching for internal changes to the ArrayCollection. Databinding is not extra smart about ArrayCollections, it is simply looking for the data setter to fire. DataProvider-driven components generally hook up a CollectionEvent handler to the ArrayCollection. You can see the code for DataGrid or List as an example.
Flex harUI is correct,you can solve your problem by using ObjectProxy class.Below is the link how to use objectproxy.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/ utils/ObjectProxy.html
North America
Europe, Middle East and Africa
Asia Pacific