Reprinted: http://hi.baidu.com/exgeztfhdnbkmwd/item/5820201b17cae1fa9d778acc
In the development of FLEX, binding is often used, and the annoying thing is that the following warning constantly appears:
Warning: Unable to bind to property 'icon 'on class 'object' (class is not an ieventdispatcher)
So what should we do? Take the following example:
<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute">
<Mx: arraycollection id = "arrcoll">
<Mx: Source>
<Mx: array id = "arr">
<Mx: Object Data = "0" label = "icon =" img/0.gif"/>
<Mx: Object Data = "1" label = "icon =" img/1.gif"/>
<Mx: Object Data = "2" label = "icon =" img/2.gif"/>
<Mx: Object Data = "3" label = "icon =" img/3.gif"/>
<Mx: Object Data = "4" label = "icon =" img/4.gif"/>
<Mx: Object Data = "5" label = "icon =" img/5.gif"/>
</MX: array>
</MX: Source>
</MX: arraycollection>
<Mx: popupbutton id = "popupbutton_pic" openalways = "true" width = "43" Height = "23">
<Mx: popup>
<Mx: titlewindow id = "titlewindow_popup" width = "450" Height = "400"
Showclosebutton = "true" verticalscrollpolicy = "on" horizontalscrollpolicy = "off" Close = "popupbutton_pic.close ();">
<Mx: toolbar width = "430">
<Mx: repeater id = "myrep" dataprovider = "{arrcoll}">
<Mx: Image id = "myimgclick" buttonmode = "true" Data = "{myrep. currentindex}" Source = "{myrep. currentitem. Icon}">
</MX: Image>
</MX: repeater>
</MX: toolbar>
</MX: titlewindow>
</MX: popup>
</MX: popupbutton>
</MX: Application>
The above example is run without errors, but there are many warnings (such as), because objet is not of the ieventdispatcher type.
The solution is as follows:
<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute" xmlns: Local = "*">
<Mx: arraycollection id = "arrcoll">
<Mx: Source>
<Mx: array id = "arr">
<Local: mycls DATA = "0" label = "" icon = "img/0.gif"/>
<Local: mycls DATA = "1" label = "" icon = "img/1.gif"/>
<Local: mycls DATA = "2" label = "" icon = "img/2.gif"/>
<Local: mycls DATA = "3" label = "" icon = "img/3.gif"/>
<Local: mycls DATA = "4" label = "" icon = "img/4.gif"/>
<Local: mycls DATA = "5" label = "" icon = "img/5.gif"/>
</MX: array>
</MX: Source>
</MX: arraycollection>
<Mx: popupbutton id = "popupbutton_pic" openalways = "true" width = "43" Height = "23">
<Mx: popup>
<Mx: titlewindow id = "titlewindow_popup" width = "450" Height = "400"
Showclosebutton = "true" verticalscrollpolicy = "on" horizontalscrollpolicy = "off" Close = "popupbutton_pic.close ();">
<Mx: toolbar width = "430">
<Mx: repeater id = "myrep" dataprovider = "{arrcoll}">
<Mx: Image id = "myimgclick" buttonmode = "true" Data = "{myrep. currentindex}" Source = "{myrep. currentitem. Icon}">
</MX: Image>
</MX: repeater>
</MX: toolbar>
</MX: titlewindow>
</MX: popup>
</MX: popupbutton>
</MX: Application>
Mycls.:
Package
{
[Bindable]
Public class mycls
{
Public var data: string;
Public var TP: string;
Public var label: string;
Public var icon: string;
Public Function mycls ()
{
}
}
}
Through the above method, you can easily solve the binding problem, and this method is called "class binding method ".