<< Chapter < Page Chapter >> Page >
Listing

Source code for quiza.as.

package CustomClasses{ import flash.events.*;import mx.containers.VBox; import mx.controls.Button;import mx.controls.RadioButton; import mx.controls.TextArea;import mx.events.FlexEvent;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 string private var correctAnswer:String;//actual stringprivate var vboxWidth:int = 375; //==================================================//public function set question(textIn:String):void{theQuestion.text = textIn; }//end implicit setterpublic function set answer(answerIn:String):void{theAnswer = answerIn; }//end implicit setterpublic function set choice0(choice:String):void{choice00.label=choice; }//end implicit setterpublic function set choice1(choice:String):void{choice01.label=choice; }//end implicit setterpublic function set choice2(choice:String):void{choice02.label=choice; }//end implicit setter//==================================================//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 //==================================================//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 //==================================================//private function vboxCompleteHandler(event:mx.events.FlexEvent):void{ //Set the height equal to the sum of the// heights of the components plus six // pixels per component to account for the// space between components. this.height =theQuestion.height + choice00.height+ choice01.height + choice02.height+ checkButton.height + result.height+ 36;//six spaces per compnent }//end vboxCompleteHandler//==================================================// }//end class}//end package

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