9/14/2010 11:54:29 PM
Title:
Checkbox issue
Hi all,
i want whenever i un-select the first hbox check box the selected checkboxes of second checkbox should also get unselected.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:HBox>
<mx:CheckBox id="cb1"/>
<mx:Label text="Train for specific sport"/>
</mx:HBox>
<mx:HBox visible="{cb1.selected}">
<mx:CheckBox />
<mx:Label text="Football"/>
<mx:Spacer width="10"/>
<mx:CheckBox />
<mx:Label text="Cricket"/>
<mx:Spacer width="10"/>
<mx:CheckBox />
<mx:Label text="Tennis"/>
<mx:Spacer width="10"/>
<mx:CheckBox />
<mx:Label text="Baseball"/>
<mx:Spacer width="10"/>
</mx:HBox>
</mx:Application>
9/15/2010 10:09:00 AM
by using radio buttons you can achieve this quite simply by just defining a group. but in case of checkbox you can write a function which checks detects the clicked checkbox and deselects the other one. I am no on my system right now , so can send you actual code if you want later .
logic would be something like this :
function checkboxClick(evt:Event):void{
if(evt.target.name== "chkbox2"){
checkbox1.selected=false
}else{
checkbox2.selected=false
}
}
9/15/2010 9:39:11 PM
Hello,
on un-select of the first checkbox also un-select second checkbox...
private function checkbox1Click(evt:Event):void
{
checkbox2.selected = false; // write code what you need
}
Regards,
Virat Patel
9/15/2010 10:21:26 PM
thanks MaxFlash and Veer,i got it, but when the data is coming dynamically and generating the checkbox based on content, i cant apply this logic as it is based on id of checkbox.
thanks
9/16/2010 2:15:06 AM
Hi,
I understand that your checkbox is dynamically.. i have made sample code may help you.
private function onCheckClick(event:MouseEvent):void
{
var cb:CheckBox = event.currentTarget as CheckBox;
if(!cb.selected)
{
for(var i:int=0; i<parentBox.numChildren; i++)
{
var disObj:DisplayObject = parentBox.getChildAt(i);
if(disObj is CheckBox && disObj != cb)
{
( disObj as CheckBox ).selected = false;
}
}
}
}
<mx:HBox id="parentBox">
<mx:Label text="Test Check Box" />
<mx:CheckBox label="cBox1" selected="true" click="onCheckClick(event)"/>
<mx:CheckBox label="cBox2" selected="true" />
<mx:CheckBox label="cBox3" selected="true" />
</mx:HBox>
Regards,
Virat Patel