我正在用 Flash 开发一个简单的程序……我遇到了复选框问题……我已经在这里搜索过,我发现一个主题说我需要什么,但我不明白该怎么做。
这是问题 Checkbox as3 功能
与此问题类似...我需要验证是否选择了我的 232 个复选框...即使按下按钮或是否选择了按钮。
任何人都可以帮助我吗?
var select:Array = new Array();
var perguntas:Array = new Array("Ch1","Ch2","Ch3","Ch4","Ch5","Ch6","Ch7","Ch8","Ch9","Ch10",);
var resposta1:Array = new Array("1","0","1","0","0","0","0","0","1","1"."0");
var resposta2:Array = new Array("1","1","0","1","0","1","0","1","0","1","1");
var resposta3:Array = new Array("1","0","0","0","0","0","0","0","0","0","0");
var resposta4:Array = new Array("0","1","0","0","0","0","1","0","1","1","0");
var i:Number;
var p1:Number;
var p2:Number;
var p3:Number;
var p4:Number;
//Create all the Checkbox
for(i = 0; i < perguntas.length; i++) {
select[i] = new CheckBox();
select[i].y = (i * 20);
**select[i].addEventListener(MouseEvent.CLICK, seleciona);**
select[i].label = perguntas[i];
select[i].width = 600;
addChild(select[i]);
}
//Verify if the checkbox are selected.
function seleciona(e:MouseEvent):void {
for(var count:Number = 0; count < select.length; count++){
if (select[count].selected == true ){
p1 += Number(resposta1[count]);
p2 += Number(resposta2[count]);
p3 += Number(resposta3[count]);
p4 += Number(resposta4[count]);
trace(p1);
}else{
trace(p1);
trace(p2);
trace(p3);
trace(p4);
}
}
}
所以我已经找到了使用按钮事件的解决方案......我很难为每个复选框设置一个事件......所以让我们简化一下
calcula.addEventListener(MouseEvent.CLICK, selecionaTeste);
function selecionaTeste(e:MouseEvent):void {
for(var count:Number = 0; count < select.length; count++){
if (select[count].selected == true ){
p1 += Number(resposta1[count]);
}
}
}