header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
cf_flex
Points:240
Posts:0

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>




1
MaxFlash
Points: 600
Posts:0
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
}

}

2
Veer
Points: 480
Posts:0
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

3
cf_flex
Points: 240
Posts:0
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

4
Veer
Points: 480
Posts:0
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


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 3+8 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions