Recipe 13.14. Retrieving Values from Checkboxes and Toggle Buttons


Problem

You want to retrieve the value from a checkbox or a toggle button.

Solution

Use the instance's selected property.

Discussion

Checkboxes and buttons that toggle provide basically the same type of functional-itythey can be selected or deselected. Each of these two types of components has a property named selected that returns either true or false. In the case of a checkbox, the selected property is true if the checkbox is checked and false if it is unchecked. The button that toggles returns TRue if the button is pressed in and false otherwise. The following code retrieves the current state of a checkbox named cchOptIn and writes it to the Output panel when the listener object's click( ) method gets called:

 var oListener:Object = new Object(); oListener.click = function(oEvent:Object):Void { trace(cchOptIn.selected); }; 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