2007.03.14...10:24 am

function to fix “class is not an IEventDispatcher” problem in Flex

Jump to Comments

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

  • Excellent fix! Just what i needed and there’s not a lot of consise information about this error…

  • Thanks for this snippet it helps a lot.

  • 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)

  • Thanks a lot!
    was almost about to redesign..saved my design


Leave a Reply