SyntaxScrewer's Blog

September 12, 2011

How the hell do I deselect a RadioButton using code in as3?

Filed under: ActionScript 3.0 — geekymaira @ 9:08 am

Ola!

So I found the need to use the RadioButton component the other day in one of the projects I was building.
I made it a part of the RadioButtonGroup and thus only one out of them could be selected at a time.

I wanted to reset all the radio buttons in a group once the group lost focus. ie. Wanted the icon to be blank.
I tried using btnInstance.selected=false. But that didn’t work.

After hunting for a solution on the internet for a while I came across this little trick that works fabulously well.

1) Just create another radio button and assign it to the same group.
2) When you want to set the selection of any of your groups radio buttons to false, just set the selected property of the new radio button added in step 1 to true!
3) Since this is a part of the RadioButtonGroup which means only 1 radiobutton can be active at all times, it deactivates all the other ones.

Short & Sweet 🙂

Cheers!
SyntaxScrewer

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: