Skip to main content
July 22, 2010
Answered

Need help with AS3 on Radio Button Quiz

  • July 22, 2010
  • 2 replies
  • 3830 views

I am trying to setup a multiple choice radio button question quiz, but I'm having issues with some of the AS and was hoping some of you could assist me. I'm fairly new to ActionScript, but I'm trying to pick up quickly. The code is listed below. The lines giving errors have been increased in size.

import fl.controls.RadioButtonGroup;


var radioGroup1:RadioButtonGroup = new RadioButtonGroup("QuestionC1");

var totalScore:int =0;

var totalCorrect:int =0;

var totalWrong:int =0;


cpr1a.label="Complete Pulminary Resuscitation";

cpr1b.label="Cardio Pulminary Resuscitation";

cpr1c.label="Cardio Pulminary Revival";

cpr1d.label="Complete Pulminary Revival";


cpr1a.group=radioGroup1;

cpr1b.group=radioGroup1;

cpr1c.group=radioGroup1;

cpr1d.group=radioGroup1;


submit_btn.addEventListener(MouseEvent.CLICK, submitClick);


function submitClick(MouseEvent):void{

if (radioGroup1.selection == null){

return;

}

if(radioGroup1.selection.label == "Cardio Pulminary Resuscitation"){

status_txt.text == radioGroup1.selection.label + " is correct!";

totalCorrect++;

score_txt.text =  "Number Correct: " + String(totalCorrect) + "\n" ;;

score_txt.appendText("Number wrong: " + String(totalWrong));

}else{

status_txt.text == radioGroup1.selection.label + " is incorrect. Sorry.";

totalWrong++;

score_txt.text =  "Number Correct: " + String(totalCorrect) + "\n" ;

score_txt.appendText("Number wrong: " + String(totalWrong));

}

}

This topic has been closed for replies.
Correct answer Ned Murphy

I can't see where that error might arise except possibly for a case where an AS2 radio is used since it appears they don't have a group property, but an AS3 radio button does.  Check to be sure that your Flash Publish Settings are set to use AS3.  AS3 errors normally have error numbers which also makes the error you quoted ring of an AS2 scenario.

Here's a link to the file I made based on your code that works fine and doesn't display the errors you mention.  It is a CS3 file.

http://www.nedwebs.com/Flash/AS3_Radios.fla

2 replies

July 22, 2010

I figured out my problem. I wasn't using radio buttons. I was using actual BUTTONS. Kinda defeats the purpose of a radio button quiz, eh? LOL!

Ned Murphy
Legend
July 22, 2010

Yep, that'll throw a wrench in the works.

Ned Murphy
Legend
July 22, 2010

What errors are you getting?  If I recreate what the code indicates exists, it works fine , except for the lines where you try to assign text to the status_txt using a comparison rather than an assignment ( status_txt.text == should use = )

July 22, 2010

It's giving me 4 errors on the lines which have been size increased. The error is the same for all lines and it reads

"Access of possibly undefined property group through a reference with static type."

Ned Murphy
Ned MurphyCorrect answer
Legend
July 22, 2010

I can't see where that error might arise except possibly for a case where an AS2 radio is used since it appears they don't have a group property, but an AS3 radio button does.  Check to be sure that your Flash Publish Settings are set to use AS3.  AS3 errors normally have error numbers which also makes the error you quoted ring of an AS2 scenario.

Here's a link to the file I made based on your code that works fine and doesn't display the errors you mention.  It is a CS3 file.

http://www.nedwebs.com/Flash/AS3_Radios.fla