This content has been marked as final. Show 4 replies
I managed to test the theory by binding the array collection to a datagrid and then adding the event to the data grid's updateComplete property in the MXML.
So how do I add an event to an array collection in a more direct manner!
I know this must be really easy, I expect I need to wait for the array collection to be initialised or have it's first data inserted or something. (I have tried = new ArrayCollection(); before adding the listener with no results)
If I have a bindable ArrayCollection and add a listner to it, then elsewhere in the code I change the ArrayCollection it's bound to by saying: someArrayColleciton = tempArrayCollection will it loose events?
If so should manually add elements?
I figured it out!!!!
After using various different methods most of them had the same problem. However if I used a timer to trace the length I could see it changing, but the event listener wasn't being triggered!
The problem was elsewhere I was setting the bound array collection like so:
bound_array_collection = new_temp_array_collection
This was then causing the event listener assigned to the bound_array_collection to be overwritten too. Even setting the source of the collection like this caused the listener to be lost.
So instead I have to now use the addItem on the array collection.
This seems to work find.
Hope this helps someone else!
We struggled with the same issue.
In our case we have an ArrayCollection that holds ArrayCollections.
This data is populated on application startup and it is indexed in the Outer ArrrayCollection by some name. If AC is an ArrayCollection in the model locator then we would add data to it as follows. Of course this is done in separate Cairngorm calls.
AC["companyInfo"] = new ArrayCollection() (xlm returned as AC)
AC["navigationInfo"] = new ArrayCollection() (xlm returned as AC)
At the same time the model locator contains another ArrayCollection used to dispatch events. This is the same design as the data AC in that it is indexed by some name.
ACLsnr["companyInfo"] = new ArrayCollection();
ACLsnr["navigationInfo"] = new ArrayCollection();
The listener ArrayCollection will always be empty but will never have its listeners destroyed each time the ArrayCollection is reloaded.
When the data is reloaded, the Cairngorm command object refreshes the ArrayCollection that holds the data and at the same time issues something like this:
var o1: ArrayCollection = model.ACLsnr["companyInfo"] as ArrayCollection;
if(o1 != null)
o1.dispatchEvent(new DataLoadEvent(parmObj.maintType + "LoadEvent", "success"));
This way, the listeners are always kept on the listener arraycollection. They can be added and removed when needed.
Hope this is clear or at least gives you an idea of how we work it.
Though it is a bit of work getting up on Cairngorm, you will not be sorry for moving to it. It lends a great deal of organization and implements some great design patterns for your application.