1 Reply Latest reply on Jun 13, 2008 3:34 PM by FlashTastic

    Dynamically creating Checkboxes

      Hi there,

      I thought I had this solved, but I can't get it working..

      I am creating an unknown number of Checkboxes, and I need to be able to reference them, and detect their state, as well as set their state.

      This is the code that creates the checkboxes:

      x=1;
      downx=5;
      while(x<10){

      //trace(x);

      temp_item="checkbox" + x;
      trace(temp_item);
      var item123:Object = my_acc.Profile1.createChild("CheckBox", temp_item, {label:myDP_array[x-1].item}) ;
      item123.setSize(400, 100);
      item123.move(0,downx);
      downx=downx+20;
      x++;
      };

      I think this is wrong because it uses the same Object to create the Checkbox. But it does actually create the checkboxes.

      But, I cant seem to reference them later.

      Any suggestions?
        • 1. Re: Dynamically creating Checkboxes
          FlashTastic Level 1
          You could create an array to hold references to the checkboxes:

          var myCheckboxes:Array = new Array();
          x = 1;
          downx = 5;
          while (x<10) {
          //trace(x);
          temp_item = "checkbox"+x;
          trace(temp_item);
          var item123:Object = my_acc.Profile1.createChild("CheckBox", temp_item, {label:myDP_array[x-1].item});
          item123.setSize(400,100);
          item123.move(0,downx);
          myCheckboxes.push(item123);
          downx = downx+20;
          x++;
          }

          Then afterwards you can loop through the array to target your checkboxes.

          Cheers,
          FlashTastic