Validating Component Data
In this task, you'll ensure that users actually make a selection before they click the Next Question button. If they don't make a selection, they'll see an error alert message and won't be able to continue.The error message is an instance of the Alert component. The Alert component can be configured with a message, title, and a selection of built-in buttons (OK, Cancel, Yes, and No). We'll use the OK button. If a user does not choose an option, we'll show the Alert component with our message, asking the user to make a selection.In order to use the Alert component, you need to have it in your project's Library. You can add it to the Library by creating an instance of the component one time. You don't need to keep the instance you create.
1. | Open the Components panel (Window > Components). Expand the User Interface group, if necessary. Double-click the Alert component to place an instance of the Alert component on the stage. If it's not already selected, click the instance and press Backspace or Delete to remove it . |


2. | Click Frame 1 of the actions layer, and press F9 to open the Actions panel. Just below the import mx.controls.Button; command near the top, add the following code: import mx.controls.Alert; |
As with the RadioButtonGroup and Button components, this code allows you to access the Alert component throughout your project using just its name, rather than its full path. It also allows you to use code hints for the component in the Actions editor window.In the next step, you'll amend the script to call the Alert component and set its parameters. The trick is to figure out how it will work. As you'll recall from earlier experiments with the trace() method, when you take the first screen of the quiz, one of five results is returned: a, b, c, d, or undefined. The latter occurs when nothing is selected, which is what you want to test. Thus, implementing this feature will consist of an if block that checks for the presence of undefined, and either calls your error alert message or proceeds to the next screen.