Flex60460
Flex60460

Reputation: 993

flex checkbox group

I need to use checkbox as radiobutton. In my case I'd like to define a checkbox group but I don't know why. If I select one checkbox, I'd like that other checkbox are deselecting

Could you help me ?

Thanks

Upvotes: 0

Views: 1977

Answers (3)

Josh
Josh

Reputation: 8159

If there is a static amount of radio buttons you need, you could use Spark States.

<s:states>
    <s:State name="check1"/>
    <s:Stage name="check2"/>
</s:States>

<s:CheckBox selected="false" selected.check1="true" click="currentState='check1'"/>
<s:CheckBox selected="false" selected.check2="true" click="currentState='check2'"/>

When you click the first one, it triggers the "check1" state in which the first check box is selected and the other is unselected. Clicking the second one does the opposite. Obviously, this is not as flexible as some would hope. But if it's for an interface element (such as an options menu), it's perfect.

States are incredibly useful if you understand how and when to use them. This past weekend, I created an all-Flex slideshow using them and it is a great example of how powerful that simple little array can be.

EDIT: I just threw together a simple app to test this, and it doesn't look like it will work using click. I'm sure you could tinker with another event to get it to work, though. Sorry this didn't work.

Upvotes: 1

Alan
Alan

Reputation: 21

I have had a requirement like this before and I used a Datagrid with Checkbox inside as itemRenderer.

I subclassed the Checkbox, overrode data getter so that each time it is clicked all the items of Datagrid are unselected, unchecked except for him. This method acquired some advantages:

  1. Flexible to add number of options programmaticcally.
  2. Display title of option group or not.
  3. Enable to use scrollbar if there is a limit of space.

Hope the solution is what you are looking for.

Upvotes: 0

Mayhem Inc.
Mayhem Inc.

Reputation: 11

I'd use RadioButtons, but if you really wanted to do it, I'd take LondonDrugs_MediaServices approach.

CheckBox and RadioButton both extend from ToggleButtonBase.

Create your own CheckBoxRadioButtonSkin. Copy the CheckBoxSkin to it and rename the hostComponent.

Then use this skin on your radioButton to make it appear to be checkbox.

Upvotes: 0

Related Questions