PDA

View Full Version : need help (again) with radio buttons!



lunatic
September 10th, 2003, 11:44 PM
So I've been very successful with radios in the past but only using two movie clips, so the code looked like this:



function radioDisplay(component) {
radio = component.getValue();
if (radio == "Blah") {
_root.A._visible = true;
_root.B._visible = false;
} else {
_root.B._visible = true;
_root.A._visible = false;
}
}\

Simple right? But what do I do if I have a whole group of movie clips? Do I have to repeat the code over and over where one is true and all the others are false?

As in:



function radioDisplay(component) {
radio = component.getValue();
if (radio == "A") {
_root.A._visible = true;
_root.B._visible = false;
_root.C._visible = false;
_root.D._visible = false;
_root.E._visible = false;
} else {
_root.B._visible = true;
_root.A._visible = false;
_root.C._visible = false;
_root.D._visible = false;
_root.E._visible = false;
}
}\

etc. etc. for each one? That seems like a major pain. Someone out there must know an easier way?

Eric Jr.
September 11th, 2003, 06:28 AM
values = ["A", "B", "C", "D", "E"];

function radioDisplay(component)
{
radio = component.getValue();
for (var i in values) _root[values[i]]._visible = false;
_root[radio]._visible = true;
}

Play with this, I can't test it, but it should work

lunatic
September 12th, 2003, 12:26 AM
Thanks for the input!

Unfortunately it didn't work. I had thought along similar lines but no luck.

Anyone else have an idea?

:trout:

Eric Jr.
September 12th, 2003, 03:06 AM
I tested it, works ... you probably don't have captioned letters in your radiobuttons..

Try changing:

radio = component.getValue();
// into
radio = component.getValue().toUpperCase();And if you want to know where your error seems to be, do a trace on the last accessed variable after each line ... to check what has changed etc.