昨天就遇到这样的现象:自定义的itemRenderer,然后定义数据类型是ArrayCollection,一发布,Console面板会输出很多这样的警告错误信息
warning: unable to bind to property 'label' on class 'Object' (class is not an IEventDispatcher)
warning: unable to bind to property 'icon' on class 'Object' (class is not an IEventDispatcher)
贴出来我自定义的itemRenderer(简化):
修改自定义的itemRenderer为下面这样,就什么都不用考虑了并且一切Ok了。
<?xml version="1.0" encoding="utf-8"?> <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ import mx.binding.utils.BindingUtils; [Bindable] private var _data:Object; [Bindable] private var _label:String; [Bindable] private var _icon:String; override public function set data(value:Object):void{ _label=value.label; _icon=value.icon; _data=value; } override public function get data():Object{ return _data; } ]]> </mx:Script> <mx:Image source="{_icon}"/> <mx:Button label="{_label}"/> </mx:VBox>
<?xml version="1.0" encoding="utf-8"?> <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ [Bindable] private var _label:String; [Bindable] private var _icon:String; override public function set data(value:Object):void{ super.data=value; if(data) { _label=data.label; _icon=data.icon; } else { _label=""; _icon=""; } } ]]> </mx:Script> <mx:Image source="{_icon}"/> <mx:Button label="{_label}"/> </mx:VBox>
转载:http://bbs.9ria.com/thread-22017-1-1.html