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

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;
}
/* ************************************* */

Advertisement

4 Comments

Filed under Adobe, ColdFusion, Flex

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

  1. Ken

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

  2. marzim

    Thanks for this snippet it helps a lot.

  3. 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)

  4. Anil

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

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s