From 2817021c560a131631cf4409e1627e2372d26906 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Thu, 18 Dec 2008 01:18:31 +0000 Subject: [PATCH] Allow to be used without a command. Alternatively, I could create a DataComboBox that just does the cool 'data' stuff, and have CommandComboBox extend that. Comment cleanups. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@746 ed5b42cb-e716-0410-a449-f6a68f950b19 --- src/as/com/threerings/flex/CommandComboBox.as | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/as/com/threerings/flex/CommandComboBox.as b/src/as/com/threerings/flex/CommandComboBox.as index 9ba8113e..9463ebf2 100644 --- a/src/as/com/threerings/flex/CommandComboBox.as +++ b/src/as/com/threerings/flex/CommandComboBox.as @@ -30,16 +30,15 @@ import com.threerings.util.CommandEvent; import com.threerings.util.Util; /** - * A combo box that dispatches a command (or calls a function) when it is toggled. NOTE: Unlike the - * other Command* controls, CommandComboBox does not guarantee that the CommandEvent is dispatched - * after notifying all other listeners. + * A combo box that dispatches a command (or calls a callback) when an item is selected. + * The argument will be the 'data' value of the selected item. + * NOTE: Unlike the other Command* controls, CommandComboBox allows a null cmd/callback + * to be specified. */ public class CommandComboBox extends ComboBox { - /** - * The field of the selectedItem object used as the argument to the - * command or function. If null, the entire selectedItem is passed as the argument. - */ + /** The field of the selectedItem object used as the 'data'. If this property is null, + * then the item is the data. */ public var dataField :String = "data"; /** @@ -103,12 +102,12 @@ public class CommandComboBox extends ComboBox */ protected function itemToData (item :Object) :Object { - return (dataField == null) ? item : ((item == null) ? null : item[dataField]); + return (item == null || dataField == null) ? item : item[dataField]; } protected function handleChange (event :ListEvent) :void { - if (this.selectedIndex != -1) { + if (_cmdOrFn != null && this.selectedIndex != -1) { CommandEvent.dispatch(this, _cmdOrFn, selectedData); } }