PDA

View Full Version : help with radio buttons?


spidermonkey
03-21-2005, 10:13 PM
I'm building a tutorial in the Flash MX (latest version) and I'm having problem with radio buttons. Ok, I haven't done much Actionscript particularly in MX. I'm a few weeks away from being sent to an Actionscript class and the books I have are really crappy. There are like a dozen examples of how to make radio buttons and all of them produce errors.

So moving right along... I'm trying to do a basic Q&A with 3 buttons like this:

What is the capital of NY?

- Boston
- Albany
- Trenton

I made these buttons by just dragging them out on to the window from the Components panel and then giving them all the group name 'rbgroupQ1'. Then I named each button instance accordingly: rbQ1, rbQ2 and rbQ3.

In my layer called 'script where I'm putting all my scripting for navigation buttons, etc., I've added this to it:

stop();

btnSubmit.addEventListener("click", mx.controls.RadioButton.addEventListener());

if (rbA2.enabled) {

trace("Correct!");

} else {

trace("Sorry, try again.");

}

When I run this though, the Output window shows:

undefined
Correct!

Am I really far off on this one? I know that in this Flash version you can drag out these components from the Learning Interactions library, but I don't want to build andentire quiz, and we're not testing students for scores on these questions. I just want to have them select a button, click on the push button and get response back.

Thanks!

spidermonkey
03-22-2005, 08:51 PM
Ok, I've finally figured this out. I'm putting this on each button (with radio2, radio3 for each successive button):

on (click) {
_root.rbresp = "radio1";
}

Then I've placed this on the pushbutton:

on (release) {

switch (_root.rbresp) {

case "radio1" :
trace ("Sorry, wrong answer. Boston is the capital of Massachusetts.");

case "radio2" :
trace ("Correct! Albany is the capital of New York.");

case "radio3" :
trace ("Sorry, wrong answer. Trenton is the capital of New Jersey.");
break;

default :
trace ("Default reached");

}
}

This works great.

Now, the only problem I'm running into is this... Instead of using the trace command, I want each condition to make a hidden label become visible on the screen.

So for each case, I've replaced the trace command with:

_root.ans1._visible = true;

where ans1 is used in case 'radio1' to bring up a label with an instance name of 'ans1' and ans2 is used in case 'radio2' to bring up a lable with instance 'ans2', etc.

However, when I run Flash and click on the first radio button, it displays the label sfor cases 1, 2 and 3. If I click on the second radio button, it makes visible the labels for case 2 and 3. Any ideas?

spidermonkey
03-22-2005, 09:15 PM
I was just missing some 'break' statements.