<< Chapter < Page | Chapter >> Page > |
Classes named QuizA and QuizB
As you can see from Listing 1 and Figure 2, two class files named QuizA.as and QuizB.as were used to instantiate the two objects shown in Figure 1. Complete listings for those two files are provided inListing 13 and Listing 14 near the end of the lesson.
Remember, this is a big-picture discussion
Because this is a "big-picture" lesson, I won't explain either of these classes in detail in this lesson. (You can find technical details for a class very similar to QuizA in Creating Online Tests using Custom ActionScript Components here you are interested in technical details at this point.) Instead, I will compare the two class definitions from a big-picture viewpoint.
For brevity, I will also delete some of the code such as import directives.
Beginning of the class named QuizA
The class named QuizA begins in Listing 2.
package CustomClasses{
//Import directives deleted for brevity.public class QuizA extends VBox{private var theQuestion:TextArea;
private var choice00:RadioButton;private var choice01:RadioButton;
private var choice02:RadioButton;private var checkButton:Button;
private var result:TextArea;private var theAnswer:String;//numeric stringprivate var correctAnswer:String;//actual string
private var vboxWidth:int = 375;
Variable declarations
The important thing to note in Listing 2 is the declaration of six instance variables of three different component types (beginning with the first line that reads private var ) . These variables will be used to hold references to the six different componentsshown in each question object in Figure 1.
TextArea, RadioButton, and Button objects
The white rectangular areas at the top and the bottom of each question object in Figure 1 is an object of the class named TextArea . You can probably spot the three RadioButton objects and the Button object in each question object.
Beginning of the class named QuizB
The class named QuizB begins in Listing 3.
package CustomClasses{
//Import directives deleted for brevity.public class QuizB extends VBox{private var components:Array =
new Array(new TextArea(),//theQuestionnew RadioButton(),
new RadioButton(),new RadioButton(),
new Button(),//checkButtonnew TextArea());//resultprivate var theAnswer:String;//numeric string
private var correctAnswer:String;//actual stringprivate var vboxWidth:int = 375;
An array with six elements
The six instance variables that I referred to in Listing 2 were replaced by a single array having six elements in Listing 3. The creation of the arraybegins with the first line in Listing 3 that reads private var .
This is the major change that was made in the implementation of QuizB relative to the implementation of QuizA . This change will have significant ramifications throughout the remainder of the code whenever it isnecessary to access a reference that points to one of the six components.
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?