今天在学习自定义事件时遇到了这样一个警告: warning: unable to bind to property 'useremail' on class 'Object' (class is not an IEventDispatcher) warning: unable to bind to property 'username' on class 'Object' (class is not an IEventDispatcher)
I found out what was happening to cause the "unable to bind" warning in the scenario that I described (see below). I eventually stumbled onto this solution after trying many different searches in Google:
--------------------------------------
This is a solution for the common warning: "unable to bind to property 'XXX' on class 'Object' (class is not an IEventDispatcher)"
This problem occurs frequently when transferring complex objects using AMF when the object returned from the server contains an array or array collection of more objects.
One symptom of this problem is that it occurs after converting the data request from an HTTPService call to a Remote Object call.
It turns out that Flex does not handle data returned from the AMF data service in quite the same way as HTTPService and WebService results. With these two later services Flex will automatically wrap Arrays in ArrayCollection and Objects in ObjectProxy wrappers so binding will work.
The solution is to do this same thing manually, with code similar to the following:
function resultHandler(result:Array) { for(var i:String in result) result[i] = new ObjectProxy(result[i]); targetArrayCollection = new ArrayCollection(result); }
Note: It may be the case that the result object is already an ArrayCollection yet the Objects in ObjectProxy wrappers. In this case you only need to include the for loop to implement ObjectProxy for all objects in the ArrayCollection.
--------------------------------------
I also discovered that if you add an object (i.e., one that you create yourself) to the ArrayCollection, then you'll also need to create an ObjectProxy for the new object or you'll get the same "unable to bind" warnings.
Hope this helps save someone else the hours I spent trying to find a solution :-)
大家看到红色标记的那一段,这是最终的解决方案
userLists=userModulLocator.userArray; for(var i:String in userLists) userLists[i] = new ObjectProxy(userLists[i]); userLists = ArrayCollection(userLists);