What happens if I drag & drop an ArrayCollection item and a XMLList item into a List ?

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&#8221; width=”100″ height=”20″>
[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:Label id=”lbl” text=”{txt}”/>

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…

P.S. This application has been constructed from the skeleton of a code-snippet that was given to me by Rajesh Bhadra


One Response to What happens if I drag & drop an ArrayCollection item and a XMLList item into a List ?

  1. Jussi Mattila says:

    I ran into a small problem in my Flex application and googling got me to your blog. I was hoping it’s just my code, but the same behavior is exhibited in your example too.

    If you drag and drop two similar items into the HList (on top of each other), the first of them is not selectable anymore. You can see that both items are in the list but the other doesn’t react to mouse anymore. Do you know a workaround for this?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s