1 Reply Latest reply on Dec 5, 2006 7:58 PM by chris.huston.t10

    checkbox labels: output

    moros3
      Yet another question about checkboxes:

      OK. So there are multiple checkboxes, each one with their own label. There is also a textarea.

      Is it possible so that when a checkbox is selected, its label is outputted to the textarea, and when the respective checkbox is deselected, its label is removed from the textarea?
        • 1. Re: checkbox labels: output
          chris.huston.t10 Level 3
          The below code will output selected checkBoxes to a textArea with each label on a new line and remove the label when it is deselected:

          private var fruit:ArrayCollection = new ArrayCollection();

          private function update_view(evt:MouseEvent):void {
          if (evt.currentTarget.selected) {
          fruit.addItem(evt.currentTarget.label);
          } else {
          fruit.removeItemAt(fruit.getItemIndex(evt.currentTarget.label));
          }
          fruit_view.text = "";
          for each (var fruit_type:String in fruit) {
          fruit_view.text += fruit_type + "\r";
          }
          }

          Here is a sample of the mxml to go with the above AS:

          <mx:CheckBox x="75" y="49" label="Apples" id="cb1" click="update_view(event)"/>
          <mx:CheckBox x="75" y="75" label="Oranges" id="cb2" click="update_view(event)"/>
          <mx:CheckBox x="75" y="101" label="Lemons" id="cb3" click="update_view(event)"/>
          <mx:CheckBox x="75" y="127" label="Grapes" id="cb4" click="update_view(event)"/>
          <mx:CheckBox x="75" y="153" label="Bananas" id="cb5" click="update_view(event)"/>
          <mx:TextArea x="172" y="48" height="123" id="fruit_view"/>

          Vygo