Thursday, April 30, 2009

The Obvious Hidden

One problem with things that are obvious is that.. they're not ALWAYS obvious to everyone, but when it comes down to finding documentation for the obvious, it's.. well... obvious so nobody WILL document it.

Here's one obvious thing in Flex 3. The combo box is very versitile and great to use. Here's one way to load it up with complex data.


private function bindAddress(data:XML):void
{
var obj:Object;
var collect:ArrayCollection = new ArrayCollection();

for each(var props:XML in data)
{
obj = new Object();
obj.Unique_ID = props.Item_Index_ID;
obj.First_Name = props.First_Name;
obj.Last_Name = props.Last_Name;
obj.Address = props.Address1 + " " + props.Address2;
obj.City = props.City;
obj.State = props.State;
obj.ZipCode = props.Zip_Code;

collect.addItem(obj);
}

cbPersons.dataProvider = collect;
}


now this will allow the user to access all of the data from the combo box by using the "selectedItem" property. For instance, you can get the Address by using.

cbPersons.selectedItem.Address

This isn't the only way to do this, but it is at least one obvious way, well documented.