Flex: Default List Item, Dynamically Populated ComboBox
I've been crazy busy, but here is a little GUI element that I have create for use in an AIR application designed to control a Flex app.
One of the features is the ability to create lists at configuration that are expressed as ComboBoxes in the application. When allowing the user to set the default, I thought it would be better to ensure that the input is valid by immediately populatig a ComboBox with the options. It is a very simple implementation, but I think the effect is pretty nifty:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable] private var _options:ArrayCollection = new ArrayCollection();
private function optionValueChanges(values:TextInput):void {
var _use:String = values.text;
if (_use.charAt(_use.length-1) == ",") {
_use = _use.substring(0,_use.length-1);
}
_options = new ArrayCollection(_use.split(","));
}
]]>
</mx:Script>
<mx:TextInput id="tiOptions" change="optionValueChanges(tiOptions)" width="150"/>
<mx:ComboBox id="cbDefault" dataProvider="{_options}" width="200" />
</mx:Application>
To make it work, just type in a comma-delimited list of items. The little bit of conditional logic is to ignore the case when the string has a trailing ",".
View a demo of the dynamically populated ComboBox for the default selection.


There are no comments for this entry.
[Add Comment]