Chapter 14. Building Advanced Flash Forms

Chapter 13 introduced building user input forms in Flash. This chapter takes that topic a few steps further by introducing advanced form features, such as data validation, prepopulating and preselecting data in form controls, dynamically populating forms, and creating responsive form elements.

14.1. Performing Actions When the User Clicks a Checkbox or Radio Button

Problem

You want your Flash application to perform some actions when the user clicks a checkbox or radio button.

Solution

Define a listener object with a click() method and register the listener with the checkbox or radio button group.

Discussion

By default, when the user clicks a checkbox or radio button, Flash doesn’t take any immediate action. In many cases, that is the behavior that you want. However, it is possible to tell Flash that you want it to perform some actions when the user clicks the checkbox or radio button control. There are a variety of reasons why you may want to do that. For example, you may want a form to automatically submit its data when the user clicks the form control rather than using a button.

In order for Flash to know to do something when the user clicks the checkbox or radio button, you need to use a listener object. You can create the listener object using the Object constructor as part of a new statement and assigning the value to a variable. The following code is an example of how you can create a listener object named oListener:

 var oListener:Object = ...

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.