From dc06c617a1992abc7a24b2e12ecdd37834ec9c5b Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Sat, 13 Dec 2008 01:45:07 +0000 Subject: [PATCH] Even more superclass style and paradigm matching. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@744 ed5b42cb-e716-0410-a449-f6a68f950b19 --- src/as/com/threerings/flex/CommandComboBox.as | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/as/com/threerings/flex/CommandComboBox.as b/src/as/com/threerings/flex/CommandComboBox.as index d350772b..9ba8113e 100644 --- a/src/as/com/threerings/flex/CommandComboBox.as +++ b/src/as/com/threerings/flex/CommandComboBox.as @@ -53,7 +53,7 @@ public class CommandComboBox extends ComboBox CommandButton.validateCmd(cmdOrFn); _cmdOrFn = cmdOrFn; - addEventListener(ListEvent.CHANGE, handleChange); + addEventListener(ListEvent.CHANGE, handleChange, false, int.MIN_VALUE); } /** @@ -75,11 +75,10 @@ public class CommandComboBox extends ComboBox /** * Set the selectedItem based on the data field. */ - public function setSelectedData (data :Object) :void + public function set selectedData (data :Object) :void { for (var ii :int = 0; ii < dataProvider.length; ++ii) { - if (Util.equals(data, - (dataField != null) ? dataProvider[ii][dataField] : dataProvider[ii])) { + if (Util.equals(data, itemToData(dataProvider[ii]))) { this.selectedIndex = ii; return; } @@ -93,15 +92,24 @@ public class CommandComboBox extends ComboBox * The value that will be passed to the command or function based on dataField and the * current selected item. */ - public function getSelectedData () :Object + public function get selectedData () :Object { - return (dataField != null) ? this.selectedItem[dataField] : this.selectedItem; + return itemToData(this.selectedItem); + } + + /** + * Extract the data from the specified item. This can be expanded in the future + * if we provide a 'dataFunction'. + */ + protected function itemToData (item :Object) :Object + { + return (dataField == null) ? item : ((item == null) ? null : item[dataField]); } protected function handleChange (event :ListEvent) :void { if (this.selectedIndex != -1) { - CommandEvent.dispatch(this, _cmdOrFn, getSelectedData()); + CommandEvent.dispatch(this, _cmdOrFn, selectedData); } }