<< Chapter < Page | Chapter >> Page > |
If you compare the code in Figure 4 and Figure 5, you will see that Figure 4 stores the incoming parameter values by way of the contents offour instance variables whereas Figure 5 stores the incoming parameter values by way of the contents of four elements in the array.
Constructor for QuizA
Listing 6 shows the constructor for the class named QuizA .
public function QuizA(){//constructor
width=vboxWidth;setStyle("borderStyle","solid");
setStyle("backgroundColor",0xffff00);theQuestion = new TextArea();theQuestion.editable = false;
theQuestion.width=vboxWidth - 2;addChild(theQuestion);
choice00 = new RadioButton();choice00.groupName="radioButtonGroup";
addChild(choice00);choice01 = new RadioButton();choice01.groupName="radioButtonGroup";
addChild(choice01);choice02 = new RadioButton();choice02.groupName="radioButtonGroup";
addChild(choice02);checkButton = new Button();checkButton.label = "Click to Check Answer";
checkButton.addEventListener(MouseEvent.CLICK,checkButtonHandler);
addChild(checkButton);result = new TextArea();result.editable = false;
result.width=vboxWidth - 2;result.visible=false;
addChild(result);//Register an event listener that will be// executed when this object has been fully
// constructed. It will set the height of// the VBox based on the sum of the heights
// of the components.this.addEventListener(
mx.events.FlexEvent.CREATION_COMPLETE,vboxCompleteHandler);
}//end constructor
There are numerous differences between the code in the constructors for QuizA and QuizB . Every statement that needs to access a reference pointing to one of the six component objects in Figure 1 is differentbetween the two constructors because of the difference in the way those references are stored. There are other differences as well, which are shown in Listing 6.
Constructor for QuizB
The constructor for the class named QuizB is shown in Listing 7.
public function QuizB(){//constructor
width=vboxWidth;setStyle("borderStyle","solid");
setStyle("backgroundColor",0xffff00);components[0].editable = false;//theQuestioncomponents[0].width=vboxWidth - 2;components[1].groupName="radioButtonGroup";
components[2].groupName="radioButtonGroup";
components[3].groupName="radioButtonGroup";//checkButton
components[4].label = "Click to Check Answer";components[4].addEventListener(MouseEvent.CLICK,checkButtonHandler);//result
components[5].editable = false;
components[5].width=vboxWidth - 2;
components[5].visible=false;
//Add GUI components to the VBox.for(var cnt:int = 0;cnt<components.length;cnt++){
addChild(components[cnt]);
}//end for loop//Register an event listener that will be
// executed when this VBox object has been fully// constructed. It will set the height of
// the VBox based on the sum of the heights// of the components.
this.addEventListener(mx.events.FlexEvent.CREATION_COMPLETE,
vboxCompleteHandler);}//end constructor
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?