That warning is confusing. It occurs because the "selectedItem"
property is an Object, and Object does not support binding. The
confusion is because it implies that XML does not support binding, while
it definitely does.
The fix is to cast/convert selectedItem to XML:
<mx:Label text="{XML(cmbCategories.selectedItem).categoryid}" />
The warning will go away.
Tracy
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of fireheadin
Sent: Tuesday, April 29, 2008 3:20 PM
To: [email protected]
Subject: [flexcoders] Unable to bind property
Hi,
I'm trying to display the categoryid of an item in a XMLListCollection
in a label for the application below and I get the following warning
message while debugging :
warning: unable to bind to property 'categoryid' on class 'XML' (class
is not an IEventDispatcher)
warning: unable to bind to property 'categoryid' on class 'XML' (class
is not an IEventDispatcher)
warning: unable to bind to property 'categoryid' on class 'XML' (class
is not an IEventDispatcher)
warning: unable to bind to property 'categoryid' on class 'XML' (class
is not an IEventDispatcher)
warning: unable to bind to property 'categoryid' on class 'XML' (class
is not an IEventDispatcher)
warning: unable to bind to property 'categoryid' on class 'XML' (class
is not an IEventDispatcher)
The application :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> "
layout="vertical" creationComplete="hsGetCategories.send()">
<mx:Script>
<![CDATA[
import mx.utils.XMLUtil;
import mx.collections.XMLListCollection;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
private var xmlListCategories:XMLListCollection;
private var xmlListCallTypes:XMLListCollection;
//Resulthandler and fault handler for get categories
private function hsGetCatRH(evt:ResultEvent):void {
xmlListCategories = new
XMLListCollection(evt.result.category);
trace(xmlListCategories);
cmbCategories.dataProvider = xmlListCategories;
cmbCategories.labelField = "categoryname";
}
private function hsGetCatFH(evt:FaultEvent):void {
trace("inside getcat error" + evt.message);
}
]]>
</mx:Script>
<mx:HTTPService id="hsGetCategories"
url="http://127.0.0.1/flex/php/getCategories.php
<http://127.0.0.1/flex/php/getCategories.php> " resultFormat="e4x"
method="POST" useProxy="false" result="hsGetCatRH(event)"
fault="hsGetCatFH(event)">
</mx:HTTPService>
<mx:ComboBox id="cmbCategories" />
<mx:Label text="{cmbCategories.selectedItem.categoryid}" />
</mx:Application>
GetCategories.php generates the following XML output :
<category>
<categoryid>1</categoryid>
<categoryname>Category 1</categoryname>
</category>
<category>
<categoryid>2</categoryid>
<categoryname>Category 2</categoryname>
</category>
<category>
<categoryid>90</categoryid>
<categoryname>Category 3</categoryname>
</category>
The Label displays the selected ID correctly however throws the
warning mentioned above. Is this OK or should I change something..
Any help will be appreciated.
Thanks and regards,
Abhishek