Add the following function definition at the end of the current script:
function clearForm() {
name_ti.text = "";
email_ti.text = "";
state_ti.text = "";
zip_ti.text = "";
errorLog_lb.removeAll();
errors.length = 0;
errorLog_lb.alternatingRowColors = null;
}
When called, this function resets the value of the scene elements. First, we remove any text that has been entered into the four TextInput instances. The next line uses the
removeAll() method of the List component to remove any error messages displayed in the
errorLog_lb instance. The next line removes any error messages stored in the
errors array. The last line sets the
alternatingRowColors property of the
errorLog_lb instance to
null. What does this do, and why are we doing it?
Setting the
alternatingRowColors property of a List component instance allows you to configure the instance to display items shown in the list with alternating row colors. This is done by creating an array with two or more color values and then setting that array as the value of the
alternatingRowColors property, such as the following:
var myArray:Array = new Array(0xFFCC00, 0xCC9900, 0x003366);
myList_lb.alternatingRowColor = myArray;
Later in this lesson we will script the
errorLog_lb instance to display error messages using alternating row colors. When the form is cleared using this function, we want the
errorLog_lb instance to revert back to its original all-white row colors. Setting the
alternatingRowColors property to
null, as this function does, takes care of that requirement.
var myColors:Array = new Array(0xCCCCCC, 0x999999);
errorLog_lb.alternatingRowColors = myColors;

errorLog_lb.alternatingRowColors = null;

In the end, the scene will be reset to its original state.