From 9d6a5f0a4a02432437b75d6805764aae2c12de1b Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Fri, 12 Dec 2008 00:18:44 +0000 Subject: [PATCH] By default, use "data" as the key in selectedItem to pass to the command. This can also be specified. If it's null, shoot the entire selectedItem as the argument. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@738 ed5b42cb-e716-0410-a449-f6a68f950b19 --- src/as/com/threerings/flex/CommandComboBox.as | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/as/com/threerings/flex/CommandComboBox.as b/src/as/com/threerings/flex/CommandComboBox.as index a9b15fe5..b0fc18ac 100644 --- a/src/as/com/threerings/flex/CommandComboBox.as +++ b/src/as/com/threerings/flex/CommandComboBox.as @@ -36,16 +36,18 @@ import com.threerings.util.CommandEvent; public class CommandComboBox extends ComboBox { /** - * Create a command combobox. The 'data' attribute of the selectedItem object is used as - * an argument of the command or function. + * Create a command combobox. * * @param cmdOrFn either a String, which will be the CommandEvent command to dispatch, * or a function, which will be called when changed. + * @param argName The attribute of the selectedItem object that used as the argument to the + * command or function. If null, the entire selectedItem is passed as the argument. */ - public function CommandComboBox (cmdOrFn :* = null) + public function CommandComboBox (cmdOrFn :* = null, argName :String = "data") { CommandButton.validateCmd(cmdOrFn); _cmdOrFn = cmdOrFn; + _argName = argName; addEventListener(ListEvent.CHANGE, handleChange); } @@ -68,11 +70,16 @@ public class CommandComboBox extends ComboBox protected function handleChange (event :ListEvent) :void { - CommandEvent.dispatch(this, _cmdOrFn, this.selectedItem.data); + if (this.selectedItem != null) { + CommandEvent.dispatch(this, _cmdOrFn, + (_argName != null) ? this.selectedItem[_argName] : this.selectedItem); + } } /** The command (String) to submit, or the function (Function) to call * when changed, */ protected var _cmdOrFn :Object; + + protected var _argName :String; } }