This is just an expansion of a previous post. The following function can be used to fix the “class is not an IEventDispatcher” problem that occurs whenever you try to bind to the items in a non-declare-class based array collection (Such as an array collection that is the result object from a remote ColdFusion query.)
If you are using the Cairngorm framework then you can add this method to your ModelLocator and have it available anywhere you need.
/* ****** applyObjectProxy ***** by: Justin Ohms
Arguments: ArrayCollection
Returns: ArrayCollection
=========================================
Adds the IEventDispatcher interface/ ObjectProxy
to the elements of the provided ArrayCollection
making those elements bindable. Usefull for
turning non bindable arraycollections
(CF Query result objects) into collections
of bindable objects.
************************************** */
public function applyObjectProxy(targetAC:ArrayCollection):ArrayCollection
{
for(var i:String in targetAC)
{targetAC[i] = new ObjectProxy(targetAC[i]);}
return targetAC;
}
/* ************************************* */
4 Comments
2007.09.27 at 9:08 pm
Excellent fix! Just what i needed and there’s not a lot of consise information about this error…
2008.05.15 at 2:12 am
Thanks for this snippet it helps a lot.
2008.11.18 at 11:55 pm
This is the solution I have been looking for. In my case I just converted the Objects to ObjectProxys prior to adding them to the ArrayCollection.
//create the objectMarker:
var objMarker:Object={
shpNum:shpNum,
Name: trimName,
ImgTxtName: trimImgTxtName,
Url:dbfReservesArray[shpNum].values.Url,
Bounds:polyBnds,
polyMarker:polyMarker,
txt:txt
}
//change Objects to ObjectProxy to get rid of warnings in the databinding:
objMarker=new ObjectProxy(objMarker);
//add item to markerArray
markerArray.addItem(objMarker);
(markerArray is an ArrayCollection)
2009.02.23 at 7:19 pm
Thanks a lot!
was almost about to redesign..saved my design