Skip navigation
untemps
Currently Being Moderated

Databinding issue

Jun 12, 2012 3:51 AM

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.

 
Replies
  • Currently Being Moderated
    Jun 12, 2012 10:17 AM   in reply to untemps

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 16, 2012 5:21 AM   in reply to untemps

    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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points