A pretty interesting question. When Rajesh Bhadra posed this question to me, I thought I should write about this. The answer is pretty straight-forward (though may not be obvious). You’ll have to handle the data type before you add/ render/ manipulate the data. i.e, your itemRenderer code will look like this
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Canvas xmlns:mx=”http://www.adobe.com/2006/mxml” width=”100″ height=”20″>
<mx:Script>
<![CDATA[
[Bindable]public var txt:String = “”;
override public function set data(value:Object):void{
super.data = value;
txt = (value is XML)? value.@name : value.name;
}
]]>
</mx:Script>
<mx:Label id=”lbl” text=”{txt}”/>
</mx:Canvas>
So, in short, the check looks like…
if(value is XML) {return value.@name}
else {return value.name}
or, converted to a ternary operator
return((value is XML)? value.@name : value.name);
A similar inspection is also needed on the selected object to extract info (as in the inspectSelection() method in code).
The application below, contains a List (with an XMLList dataProvider and a labelFunction) and a TileList (with an ArrayCollection dataProvider and an itemRenderer). The third control is a HorizontalList with the itemRenderer code that i mentioned earlier.
You can drag & drop from the List & Tile to the HList without data loss… that’s the idea. For details…
- The Application
- Basic MXML Source Code
- HListItemRenderer
- Thumbnail (itemRenderer for TileList)
P.S. This application has been constructed from the skeleton of a code-snippet that was given to me by Rajesh Bhadra
Posted by raghunt 
