Recipe 13.15. Retrieving Values from Radio Button GroupsProblemYou want to retrieve a value from a group of radio buttons. SolutionUse the radio button group's selectedData property. DiscussionAs discussed in Recipe 13.5, radio buttons are typically used in groups. Therefore, you usually will want to retrieve the value from the selected radio button in the group. In order to do that, all you need to do is use the selectedData property of the radio button group. Recall that when you create a radio button instance, you set the groupname (exp 3pod.com) parameter. The groupname (exp 3pod.com) parameter defines how the radio buttons are associated. Not only that, but it also creates a new ActionScript object with that same name (exp 3pod.com). For example, if you create five radio buttons and assign each of them the group name (exp 3pod.com) of rbgQuizQuestion, Flash will automatically create an ActionScript object named rbgQuizQuestion. You can later use that ActionScript object to retrieve the value that has been selected for the entire group of five radio buttons. That object has a property named selectedData that will return the chosen value. If you have defined a data parameter value for the radio buttons, the radio button group's selectedData property will return the data value for the selected radio button. However, if you have not defined the data parameter value for the radio buttons, the selectedData property will simply return the chosen radio button's label value. In most scenarios, you will want to retrieve the selected radio button value only after the user has clicked a submit button or some other similar event indicating that the form data should be processed. The following code is an example in which the selected value from a radio button group named rbgQuizQuestion is displayed in the Output panel when the user clicks on a button: var oListener:Object = new Object(); oListener.click = function(oEvent:Object):Void { trace(rbgQuizQuestion.selectedData); }; cbtSubmit.addEventListener("click", oListener); See AlsoRecipe 13.5 |
Tripod >> 3pod Tips & Learning and manuals for educations