<< Chapter < Page Chapter >> Page >

In addition to the differences in the way that references to the six component objects are accessed, Listing 7 contains other significant differences aswell.

No code to instantiate the six component objects

First, there is no code in Listing 7 to instantiate the six component objects. As I mentioned earlier, those objects wereinstantiated and used to populate the six-element array referred to by components when the array was created.

Only one statement calling the addChild method in QuizB

Next, you will notice that there are six statement making calls to the addChild method of the VBox container in Listing 6. Calls to that method cause the components to be added as children of the container.

Those six calls to the addChild method were consolidated into a single call inside a for loop in Listing 7. This is possible because the six references are contained in an array whoseelements can be accessed using a numeric index.

The checkButtonHandler for QuizB

Listing 8 shows the checkButtonHandler method for the class named QuizA .

The checkbuttonhandler for quiza.

private function checkButtonHandler( event:MouseEvent):void{result.visible=true;if(theAnswer == "0"){ correctAnswer = choice00.label;}else if(theAnswer == "1"){ correctAnswer = choice01.label;}else{ correctAnswer = choice02.label;}//end elseif((theAnswer=="0"&&choice00.selected) || (theAnswer=="1"&&choice01.selected) || (theAnswer=="2"&&choice02.selected)){result.setStyle("color",0x00ff00); result.text = "Correct\nCorrect Answer is: "+ correctAnswer; }else{result.setStyle("color",0xff0000); result.text = "Wrong\nCorrect Answer is: "+ correctAnswer; }//end else}//end checkButtonHandler

This is the event handler method that is registered for a click event on the Button by the code in Listing 6.

The checkButtonHandler for QuizB

Listing 9 shows the corresponding checkButtonHandler method for the class named QuizB .

The checkbuttonhandler for quizb.

private function checkButtonHandler( event:MouseEvent):void{components[5].visible=true;if(theAnswer == "0"){correctAnswer = components[1].label;}else if(theAnswer == "1"){ correctAnswer = components[2].label; }else{correctAnswer = components[3].label;}//end elseif((theAnswer=="0"&&components[1].selected) ||(theAnswer=="1"&&components[2].selected) ||(theAnswer=="2"&&components[3].selected)){components[5].setStyle("color",0x00ff00); components[5].text = "Correct\nCorrect Answer is: "+ correctAnswer; }else{components[5].setStyle("color",0xff0000);components[5].text = "Wrong\nCorrect Answer is: "+ correctAnswer; }//end else}//end checkButtonHandler

This is the event handler method that is registered for a click event on the Button by the code in Listing 7.

Differences between the code

The differences between the methods named checkButtonHandler in the two classes result from the different access requirements for the three radiobuttons and the text area at the bottom of the question objects in Figure 1.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with actionscript. OpenStax CNX. Jun 04, 2010 Download for free at http://cnx.org/content/col11202/1.19
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?

Ask