Chinaunix首页 | 论坛 | 博客
  • 博客访问: 194755
  • 博文数量: 76
  • 博客积分: 2500
  • 博客等级: 少校
  • 技术积分: 490
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-12 16:58
文章分类

全部博文(76)

文章存档

2011年(3)

2010年(52)

2009年(21)

我的朋友

分类:

2010-05-07 21:26:31

今天在学习自定义事件时遇到了这样一个警告:
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)

在非调试状态下,这个是不会显示的,我也运行了书本上一个经典的例子,也有同样的问题,是什么原因引起的呢?

程序代码


        
            
        


userLists是一个ArrayCollection,从表面上很难看出是什么原因,经过google,发现很多都提到了ObjectProxy,但都没有完整而有针对性的方案,最后看了一篇这样的文章:

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

经过调整,警告消失了,而这里只是用了一个对象代理!至于ObjectProxy,也是第一个看到和用到,还有待进一步的学习! 
阅读(1327) | 评论(1) | 转发(0) |
0

上一篇:flex 中使用Cookie

下一篇:synchronized

给主人留下些什么吧!~~

smalldai2013-01-28 01:45:17

在类的生命中中增加[Bindable]也可以解决,具体的原因没有深究,不过你可以试试~
[Bindable]
public class PageVo  extends BasicVo