[mx] modifying checkboxes component code to assign single variables

RE : code taken from Kirupa.com’s form tutorial
here is my published swf

Hi, could anyone help me modify the code for these checkbox components?

right now, the SUBMIT button checks which ones of the checkboxes are checked and gets their label, then
writes the appropriate labels in a dynamic text box.

// HERE IS THE CODE FOR THE Checkbox Components-----------

// Array of the instance names of the checkboxes
myCheck = [one,two,three,four,five,six,seven,eight,nine]; // Function
function checkDisplay(component) {
var j,s;
for(j in myCheck){
if(myCheck[j].getValue()) s += myCheck[j].getLabel()+"
";
}
checke = ((s.length) ? s : “Nothing”);
}

// As usual…
for (i=0;i<myCheck.length;i++) {
myCheck*.setChangeHandler (“checkDisplay”) ;
}

// Push Buttons
// ---------------

// Reset button function
onReset = function () {
// checkbox
var j;
for (j in myCheck) {
myCheck[j].setValue(false);
//vider la boite texte
result.text = “”;
}

}
// Submit button function
onSubmit = function () {
texte = comment.text;

//to make choice appear in dynamic text box
result.text+= checke;

}

For the program I am doing, I need to have a maximum of 6 checkmarks and each one of the checked label must
go into its own variable. (see gray part of the swf)
I would also like the labels to appear in the right order, right now it’s inversed.

please see source file:

FLA source file

thanks…a lot! :slight_smile:
-Isabelle

If anyone is interested, someone finally helped me solve this problem using arrays.

My checkboxes are into a movie clip called “ensemble” and “validation” is the function of my Submit (pushbutton component).

function validation()
{
//create array
tableau=new Array();

//prepare index
ind=“0”

//let’s say we have approx.20 checkboxes
for(i=1;i<=20;i++)
{
//take value
val=_root.ensemble[“chk”+i].getValue();

  //if true
  if(val==true) 
  { 
     //send it into an array
     tableau[ind]=_root.ensemble["chk"+i].getLabel(); 
      
     //trace(_root.ensemble["chk"+i].getLabel()) 
      
     //go to new index.
     ind++; 
      
   
  } 

}
trace(tableau);
}

then you can assign variables and text fields using :
newvariable = tableau[5] (for example) and you don’t have to use the whole array, just [0] to [5] for six variables. Great!

-Isa :thumb: