View Full Version : to limit selection of checkboxes
sskstorm
October 16th, 2009, 06:55 AM
Hi there
Does anyone know how to maintain a limit on the no. of checkboxes to be selected?
In my case, there are 8 checkboxes and user has to select any 4 of these.
Please reply.
flyingmonkey456
October 16th, 2009, 07:42 AM
create a variable; raise it by one every time a checkbox is checked and lower it by one every time one is deselected. when you click to select a checkbox, check the variable before you check it. so something like:
on click{
if(Checkboxes =< MaxCheckboxes and selected == false){
select check box
Checkboxes++
}
if(selected == true){
deselect checkbox
Checkboxes--
}
}
sskstorm
October 16th, 2009, 01:45 PM
Hi flyingmonkey456!
Thanks a lot for your reply.
I got inspired by it and used a different method using arrays and a for-loop and it worked!
I am creating an objective-based game with a job interview scenario in Flash CS4 and ActionScript 3.0.
The basic structure is given below if people out there need it:
var array = [oneBox, twoBox, threeBox, fourBox];
var count:int = 0;
var i:int;
// For selecting a maximum of 2 checkboxes out of 4.
for(i = 0; i <= 3; i++)
{
if(array[i].selected == true)
{
count++;
}
}
if(count > 2)
{
gotoAndStop("current scene");
}
if(count == 2)
{
gotoAndStop("next scene");
}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.