View Full Version : [AS3] How to deselect radio button w/ AS
SergeantFlash
12-11-2008, 12:04 AM
I have a RadioButton on the stage. I want it so that when someone clicks on it (selects it) and then presses my continue button that the RadioButton is no longer selected. Thanks.
edit: woops, i though i was posting this in the AS 3 forum.
SergeantFlash
12-11-2008, 12:26 AM
I have a RadioButton on the stage. I want it so that when someone clicks on it (selects it) and then presses my continue button that the RadioButton is no longer selected. Thanks.
CyanBlue
12-11-2008, 01:09 AM
You were... I moved it to the Components forum because that's where your question belongs... Let's make sure that we post the question to the most appropriate forum...
I am confused on what you are really trying to do... Are you trying it so that you are basically wanting to disable the RadioButton once the user clicks on the Continue button???
If that is the case, you can use enabled property to disable it...
caseyctg
12-14-2008, 04:55 PM
Not sure what you are trying to do either, but my best guess is you want the radio button to have an option where nothing is selected. I've found with radio buttons, something always has to be selected as a default. Look below at the smiley face icons. There is a no icon default. With radiobuttons, you must select something at all times. radiobuttons do allow you to select them using:
RadioButtonInstance.select
not sure if you are trying to get rid of the radio button on click or just deselect it...if you are trying to get it off stage, you could use this:
myBtn.addEventListener(MouseEvent.CLICK, btnListener)
function btnListener(event:Event)
{
RadioButtonInstance.visible = false;
}
but if you are trying to deselect it, you may have to set a default value like this:
myBtn.addEventListener(MouseEvent.CLICK, btnListener)
function btnListener(event:Event)
{
RB1.selected=true;
RB2.selected=false;
RB3.selected=false;
}
this will select the first radiobutton, and deselect the other two.
you could also do a enabled, which will grey it out and make it so it cannot be selected
myBtn.addEventListener(MouseEvent.CLICK, btnListener)
function btnListener(event:Event)
{
RB1.selected=true;
RB1.enabled=false;
RB2.selected=false;
RB3.selected=false;
}
sl33pwalker
12-19-2008, 03:59 PM
It isn't documented, it isn't intentional, and there is nothing that says that at least one has to be selected. I understand what the desired result is. I am attempting to reuse RadioButtons and once one is selected, whether explicitly in a group or not, you cannot unselect it (easily).
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/controls/RadioButton.html#selected
crsolem
05-01-2009, 01:39 AM
I'm no expert myself and spent the day trying to figure out how to do the same thing. What I eneded up doing was creating an extra radio button and set it's visibility to false. I was then able to set it's selected property to true which deselected the other buttons.
DukeW
06-12-2009, 11:42 AM
Here is the solution that i found. (Its for those who don't want to place an extra hidden RadioButon)
Flash CS3(AS3):
import fl.controls.RadioButtonGroup;
var rg:RadioButtonGroup= RB1.group;
button.addEventListener(MouseEvent.CLICK,deSelect)
function deSelect(e:Event)
{
rg.selection=new RadioButton();
}
Same code does not work in Flash CS4
To achieve the same goal in CS4:
import fl.controls.RadioButtonGroup;
var rg:RadioButtonGroup= RB1.group;
button.addEventListener(MouseEvent.CLICK,deSelect)
function deSelect(e:Event)
{
var tempR:RadioButton = new RadioButton()
tempR.group = rg;
tempR.selected = true;
}
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.