1 Reply Latest reply on Dec 10, 2008 12:02 PM by ntsiii

    addChild() during a repeater loop

    Ethan Kurtz
      In a nested repeater loop, I'm outputting answer choices to the questions that make up the outer repeater loop. To make the application dynamic, I am using different answer choice formats (checkbox, radio, etc) in the form of custom components as children of the repeater. When I simply hardcode an entry for the component inside repeater tags, it works just fine. However, since I don't know which component type will show up when the repeater runs, I'm calling a function on repeat that passes in the answer text so I can use it as part of the custom component. I can create the component but it does not get added to the container that the repeater is looping inside of (a vBox). Any ideas?


      private function chooseFieldType(answerText):void{
      // switch based on question type
      switch (questionsArray.getItemAt(questionContainer.selectedIndex).answerType){
      case "checkbox":
      var thisCheckBox:chkBx = new chkBx();
      thisCheckBox.textBoxText = answerText;


      I've tried repeater.addChild(thisCheckBox) and nothing shows....

      Any help would be greatly appreciated!

        • 1. Re: addChild() during a repeater loop
          ntsiii Level 3
          "...calling a function on repeat ..." I am not sure what you mean, but don't do that.

          Do it inside the repeated component.

          You should have two components. One is the Question component, the other is the Answer component. The outer application contains the repeater that repeats Question. Question contains the repeater that repeats Answer.

          The outer repeater should pass the currentItem(a Question Item) into the Question component. Question should use that data to create the question text. It should also use that data to get the dataProvider for the Answers repeater.

          Answer component should have a public property "answerType" (and others as necessary, to display the answer.), implemented as a setter function. The setter function should use that value to determmine what kind of control to display.

          I suggest you use either states of ViewStack to switch between control types. I am more comfortable with ViewStack myself.

          So the setter might look like this:
          public function set answerType(sValue:String):void {
          switch (sValue){
          case "checkbox":
          myViewStack.selectedIndex = 0;
          case "textinput":
          myViewStack.selectedIndex = 1;