Recipe 13.12. Retrieving Combo Box, Single-Select List, and Numeric Stepper ValuesProblemYou want to retrieve the selected value from a combo box, a single-select list, or a numeric stepper. SolutionUse the instance's value property. DiscussionCombo 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 (exp 3pod.com): var sProductname (exp 3pod.com):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 (exp 3pod.com) 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); |
Tripod >> 3pod Tips & Learning and manuals for educations