With the Actions panel still open, add the following function definition at the end of the current script:
function validateForm() {
errorLog_lb.removeAll();
errors.length = 0;
validateName();
if (errors.length > 0) {
errorLog_lb.defaultIcon = "errorIcon";
var altColorArray:Array = new Array(0xF9F2F2, 0xECD9D9);
errorLog_lb.alternatingRowColors = altColorArray;
errorLog_lb.rollOverColor = 0xFFFFFF;
errorLog_lb.selectionColor = 0xFFFFFF;
errorLog_lb.dataProvider = errors;
} else {
gotoAndStop ("Confirm");
}
}
In Step 2, we created a validation function to check the data entered into the
name_ti instance. As we progress through this lesson, we'll create several more validation functions to validate the data entered into our other TextInput instances. The function created in this step
validateForm()is really the mother of all these other functions; eventually it will be used to call all the individual validation functions and then finalize the validation process, including outputting error messages to the
errorLog_lb List component instance. Take special note of the sequence of actions in this function: This flow plays an important role in how the function works.
The first two actions in this function clear the
errorLog_lb instance of any displayed errors as well as any messages that might exist in the
errors array. Obviously, the first time the form is validated, these actions are worthless because both begin empty. Any subsequent validation of the entered data will require that the
errorLog_lb instance begin the validation process empty of any displayed items, and that any error messages in the
errors array be erased.
The next line contains a function call to the
validateName() function we defined in Step 2. This will cause that function to execute and validate the data in the
name_ti instance. As a result, an error message is pushed into the
errors array if data is invalid.
Note
We will add more function calls as we define them in the following exercises.
The next action in this function is an
if statement, which is evaluated only after the
validateName() function has completed its job. This is where the sequence of actions becomes important. If an error message is pushed into the
errors array as a result of calling the
validateName() function, the
length property of the
errors array is changed to 1, indicating that it contains one error message. This
if statement then looks at the
length property of the
errors array and then acts accordingly. If the
length property has a value greater than 0 (indicating error messages within the array), the resulting actions output those messages to the
errorLog_lb List component instance. If
errors.length is 0, this means there are no error messages and the data is valid; therefore, a
gotoAndStop() action sends the Timeline to the frame labeled Confirm.

The actions used to output the error messages are fairly straightforward. The first action sets the
defaultIcon property of the
errorLog_lb instance. The value of this property is the identifier name of a movie clip in the library that will appear next to every item shown in the list. We've set the value of this property to
"errorIcon". This is the identifier name of a movie clip in the library that looks like a round circle with an
X in the middle.

The next two lines of script set the
alternatingRowColors property of the
errorLog_lb instance. As explained in Step 3 of the preceding exercise, an array is created that holds two or more color values (in this case,
altColorArray). That array is then set as the
alternatingRowColors property of the
errorLog_lb instance. As a result, the rows in that instance will alternate between the colors listed in the
altColorArray array.
The next two lines of the script set the color values used when items in the
errorLog_lb instance are rolled over or selected.
Finally, the last line sets the
dataProvider property of the
errorLog_lb instance. As you can see, we set the
errors array as the value of this property. As a result, any error messages contained in that array will show up as individual items in the list.