How can I set a function to be called when the length of a DataProvider changes?
Asked
Active
Viewed 3,886 times
3 Answers
1
Here is a good solution using the event "CollectionEvent.COLLECTION_CHANGE" :

Dunaril
- 2,757
- 5
- 31
- 53
-
I tried adding this event listener to the List, but it didn't get called. After adding it to the List's data provider, it got called once but didn't get called after more changes. – Anonymous1 Feb 06 '11 at 15:29
-
Could you add some code in your question? Indeed you should add the event listener to the data provider. Check whether you do not create a new data provider at any moment, in which case the new provider will not keep the event subscription. – Dunaril Feb 06 '11 at 15:33
-
I'm using drag and drop with two lists. It's somewhat similar to the second example here: http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7cfd.html – Anonymous1 Feb 06 '11 at 15:37
-
If a new dataProvider is set at runtime you will have to re-add your COLLECTION_CHANGE listeners, but that will be tricky because DataGroup offers no events or notification that something has set it a new dataProvider. I would look for a more elegant solution. – Jonathan Dumaine Feb 07 '11 at 22:33
0
The only way I could get thru it was making a binding in the actionscript code. Something like this:
protected function creationCompleteHandler(event:FlexEvent):void {
BindingUtils.bindSetter(myHandleFunction, myList, "dataProvider");
}
myHandleFunction receives by parameter an object with the type of the binded property.
0
If you're working with an ICollectionView (aka ArrayCollection), you could add an event listener for the "collectionChange" event.
If you are inside an MXML document the dataProvider property of the UI component should be a source of data binding. So you could just {myComponent.dataProvider.length} bind the value to something else if that is the use case.

Shakakai
- 3,514
- 1
- 16
- 18