Recipe 13.12. Retrieving Combo Box, Single-Select List, and Numeric Stepper Values


Problem

You want to retrieve the selected value from a combo box, a single-select list, or a numeric stepper.

Solution

Use the instance's value property.

Discussion

Combo boxes, single-select lists, and numeric steppers all have a property named value that returns the currently selected value from the component. With combo boxes and lists the value property returns the data value that corresponds to the selected item if the data value is defined. If no data value is defined for that item, it returns the label instead. Numeric steppers return the currently selected numeric value.

The following retrieves the value from a combo box named ccbProducts and saves it to a variable named sProductName:

 var sProductName:String = ccbProducts.value; 

In most cases, of course, you want to retrieve the selected value only when the user clicks on a button in the form to submit the data for processing. Therefore you should place the ActionScript code within a listener object's click( ) method or a button instance's onRelease( ) event handler method. The following example uses a listener object to display the value from a numeric stepper name cnsQuantity in the Output panel when the user clicks on a button component instance named cbtSubmit:

 var oListener:Object = new Object(); oListener.click = function(oEvent:Object):Void {   trace(cnsQuantity.value); }; cbtSubmit.addEventListener("click", oListener); 




Flash 8 Cookbook
Flash 8 Cookbook (Cookbooks (OReilly))
ISBN: 0596102402
EAN: 2147483647
Year: 2007
Pages: 336
Authors: Joey Lott

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net