PDA

View Full Version : Radio button change event?



jarmanje
February 15th, 2008, 09:08 PM
Hi there...
for some reason, my code thinks everytime i am selecting radio1 (the first button)??
It can't detect the other 2 buttons!

Please help me solve this.. Any help is appreciated


I have 3 radio buttons in one mc
radio1 (value = good) radio2 (value = big) radio3 (value = small)

All in the same group "radioGroup1"

here is my code:

radio1.addEventListener(Event.CHANGE, changeHandler1)
function changeHandler1(event:Event):void {

if(event.currentTarget.value=="good")
{
trace(event.currentTarget.value)
combo.visible = false;
}
else
{
trace(event.currentTarget.value)
combo.visible = true;
}
}

jarmanje
February 19th, 2008, 07:26 AM
I made a small example file with my problem.. as you see, the combo boxes do not appear when the radio2 or radio3 are selected...

http://www.yoce.com/radioproblem.fla

saion
February 19th, 2008, 07:37 AM
The sollution is that you have to add the listener to all of the RadioButtons.

radio1.addEventListener(Event.CHANGE, changeHandler1)
radio2.addEventListener(Event.CHANGE, changeHandler1)
radio3.addEventListener(Event.CHANGE, changeHandler1)

Then it should work fine!

saion
February 19th, 2008, 07:41 AM
Or add an eventListener to the goup by doing this:

radio1.group.addEventListener(Event.CHANGE, changeHandler1)

function changeHandler1(event:Event):void {

var theValue : String = event.currentTarget.selection.value;

if(theValue=="good")
{
trace(theValue)
combo.visible = false;
}
else
{
trace(theValue)
combo.visible = true;
}
}

jarmanje
February 19th, 2008, 08:10 AM
Youre a legend!

Tak!