128 Syntax and Language Fundamentals
4. Save the class file.
5. Select File > New and click Flash Document to create a new FLA file.
6. Save the new FLA file as student_test.fla.
7. Type the following ActionScript on Frame 1 of the main Timeline:
// student_test.fla
import Student;
var firstStudent:Student = new Student("cst94121", "John", "H.", "Doe");
trace(firstStudent.firstName); // John
firstStudent.firstName = "Craig";
trace(firstStudent.firstName); // Craig
8.
Select File > Save to save the changes to student_test.fla.
9. Select Control > Test Movie to test the FLA and AS files.
The next example demonstrates how curly braces are used when you work with functions.
To use curly braces with functions:
1. Select File > New and select Flash Document to create a new FLA file.
2. Select File > Save As and name the new file checkform.fla.
3. Drag an instance of the Label component from the Components panel onto the Stage.
4. Open the Property inspector (Window > Properties > Properties) and with the Label
component instance selected, type an instance name of status_lbl into the Instance Name
text box.
5. Type 200 into the W (width) text box to resize the component to 200 pixels wide.
6. Drag an instance of the TextInput component onto the Stage and give it an instance name
of firstName_ti.
7. Drag an instance of the Button component onto the Stage and give it an instance name of
submit_button.
8. Select Frame 1 of the Timeline, and add the following ActionScript into the Actions panel:
function checkForm():Boolean {
status_lbl.text = "";
if (firstName_ti.text.length == 0) {
status_lbl.text = "Please enter a first name.";
return false;
}
return true;
}
function clickListener(evt_obj:Object):Void {
var success:Boolean = checkForm();
};
submit_button.addEventListener("click", clickListener);