Reputation: 129
I have 16 checkboxes and I need to see which of them was selected. Is there a function that can do that ? I am able to do them with if() but it will be way to long thanks for the help !!
Upvotes: 0
Views: 1127
Reputation: 208
You should enumerate checkboxes with progressive index, so you can cycle them with a simple for. For example:
//Your checkboxes
var cb1:CheckBox = new CheckBox();
addChild(cb1);
var cb2:CheckBox = new CheckBox();
addChild(cb2);
var cb3:CheckBox = new CheckBox();
addChild(cb3);
var cb4:CheckBox = new CheckBox();
addChild(cb4);
var cb5:CheckBox = new CheckBox();
addChild(cb5);
...
private function getSelectedCb():Array
{
var returnArray:Array = new Array();
for(var i:uint = 1; i < 6; i++)
{
var c:CheckBox = this["cb" + i] as CheckBox;
if(c != null && c.selected)returnArray.push(c);
}
return returnArray;
}
Function getSelectedCb()
return array containing all selected checkboxes.
I hope this could be usefull to you!
Upvotes: -2
Reputation: 22604
Put your checkboxes in an array, then create a function to iterate over the array and see which box was selected (you can use "for each" and "if"). Add all selected ones to a new array and use this as the function's return value.
Upvotes: 4