get/setSelectedValue for modifying the index based on the data of an option.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@740 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Bruno Garcia
2008-12-13 00:14:01 +00:00
parent 7ecec007c8
commit fb3836d104
+30 -3
View File
@@ -72,11 +72,38 @@ public class CommandComboBox extends ComboBox
_cmdOrFn = fn;
}
/**
* Handy function to lookup an option based by argName and set it as the selected item.
* This probably only works for Array dataProviders.
*/
public function setSelectedValue (value :Object) :void
{
for (var ii :int = 0; ii < dataProvider.length; ++ii) {
var v :Object = (this.argName != null) ?
dataProvider[ii][this.argName] : dataProvider[ii];
if (v == value) {
this.selectedIndex = ii;
return;
}
}
// Assign to the prompt
this.selectedIndex = -1;
}
/**
* The value that will be passed to the command or function based on argName and the
* current selected item.
*/
public function getSelectedValue () :Object
{
return (this.argName != null) ? this.selectedItem[this.argName] : this.selectedItem;
}
protected function handleChange (event :ListEvent) :void
{
if (this.selectedItem != null) {
CommandEvent.dispatch(this, _cmdOrFn,
(this.argName != null) ? this.selectedItem[this.argName] : this.selectedItem);
if (this.selectedIndex != -1) {
CommandEvent.dispatch(this, _cmdOrFn, getSelectedValue());
}
}