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-ity—they 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);
Get Flash 8 Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.