3 Replies Latest reply on Aug 30, 2011 10:47 PM by Flex harUI

    ItemRenderer - removing dataProvider (ArrayCollection) objects




      Heres my situation: I have an ArrayCollection which is being used as a data provider for a spark List control which also uses an itemRenderer. The ArrayCollection object is a part of my bussiness model and is exposed to the UI as a bindable property and since i try to keep my UI code separated from the logic/model i assign the ArrayCollection to the dataProvider object inside the creationComplete handler for the component which also includes the spark list and thats it.


      As the program runs some items are added to the array collection (inside the model), and they are rendered inside the list correctly. Later on, some of the items(objects) in the array collection may be removed from it using collection.RemoveItemAt(collection.getItemIndex(item)), and when this happens program crashes saying that itemRenderer caused a null object error (basically, it tried to render itself but the object it was using to do so was not there --> it was removed from inside the model).


      However, then i just tried this: i removed all items like this: listControl.dataProvider.RemoveAll(); and there was no error. I dont understand why, because dataProvider of the list is a reference to the same arrayCollection, it's as if the itemRenderer only knew that the objects it was renderering were removed only if they were removed through the dataProvider property of the list. The model is not static, it extends eventDispatcher and is declared bindable, also nothing is wrong until i remove objects from AC.


      I dont want to modify my model from the UI, does anyone have any ideas why this behavior?


      Thank you