title: How to check the user selections on dynamically generated radio buttons and check boxes in Flex?
body: <p>The following is my codes.  This is still work in progress; so, you will see some functions with empty contents.  Plus, this is my first Flex application; please bear with me.</p>
  
  <p>This is a quiz application that gets the questions and answers to each questions from a ColdFusion web service.  There are three types of questions, True or False, Multiple Choice with single selection, and Multiple Choice with multiple selections.  So, based upon the question type, the application would dynamically generate the appropriate amount of radio buttons or check boxes for the users to select.  I got these working.  The problem that I am having is, I am not sure how to check what the users have actually selected.  In some other forums and posts on other web site, it said that I can use event.currentTarget.selectedValue to get the user selection.  But when I actually do it, I got a run-time error saying, "Property selectedValue not found on mx.controls.FormItem and there is no default value."  My question is, what do I need to do to capture the user selections?</p>
  
  <p>Thanks in advance,</p>
  
  <p>Monte</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx"
    creationComplete="initVars()"&gt;
      &lt;fx:Declarations&gt;       
        &lt;s:RemoteObject id="CFCertService" destination="ColdFusion" source="CFCertExam.cfquiz"&gt;
          &lt;s:method name="returnQuestions" result="resultHandler(event)"/&gt;
          &lt;s:method name="returnAnswers" result="answerHandler(event)"/&gt;
        &lt;/s:RemoteObject&gt;
      &lt;/fx:Declarations&gt;
      &lt;fx:Script&gt;
          &lt;![CDATA[
              import mx.collections.ArrayCollection;
              import mx.containers.FormItem;
              import mx.controls.Alert;
              import mx.controls.CheckBox;
              import mx.controls.RadioButton;
              import mx.rpc.events.ResultEvent;
              import mx.rpc.remoting.RemoteObject;
  
              [Bindable]
              private var questionArray:ArrayCollection;
              private var questionType:String;
              private var answerItem:FormItem;
  
              [Bindable]
              private var currentQuestionCounter:int;
  
              [Bindable]
              private var answerArray:ArrayCollection;
              private var myOptionButton:RadioButton = new RadioButton();
              private var myOptionButton2:RadioButton = new RadioButton();
  
              private function initVars():void {
                  currentQuestionCounter = 0;
                  btnPrev.enabled = false;
                  btnNext.enabled = false;
              }
  
              private function answerHandler(event:ResultEvent):void {
                  answerArray = event.result as ArrayCollection;
                  var i:int;
                  answerForm.removeAllChildren();
                  answerItem = new FormItem();
                  answerForm.addChild(answerItem);
  
                  switch (questionType) {
                      case "True or False":
                      {   
                              myOptionButton.label = "True";
                              if (answerArray.getItemAt(0).Answer_Choice == "True") {
                                myOptionButton.value = 1;
                              } else {
                                  myOptionButton.value = 0;
                              }
  
  
                              answerItem.addChild(myOptionButton);                            
  
                              myOptionButton2.label = "False";             
                              if (answerArray.getItemAt(0).Answer_Choice == "False") {
                                  myOptionButton2.value = 1;
                              } else {
                                  myOptionButton2.value = 0;
                              }
                              answerItem.addChild(myOptionButton2);                       
                              answerItem.addEventListener(MouseEvent.CLICK, selectionHandler);                            
                              break;
                      }
  
                      case "Multiple Choice (Single Selection)":
                      {
                          for (i=0; i&lt;answerArray.length; i++) {
                              var myOptionButton1:RadioButton = new RadioButton();
                              myOptionButton1.label = answerArray.getItemAt(i).Answer_Choice; 
                              if (answerArray.getItemAt(i).Corect_Flag == "1") {
                                  myOptionButton1.value = 1;
                              } else {
                                  myOptionButton1.value = 0;
                              }                           
                              answerItem.addChild(myOptionButton1);                           
                          }
                          break;
                      }
  
                      case "Multiple Choice (Multiple Selection)":
                      {
                          for (i=0; i&lt;answerArray.length; i++) {
                              var myCheckBox:CheckBox = new CheckBox();
                              myCheckBox.label = answerArray.getItemAt(i).Answer_Choice;             
                              answerItem.addChild(myCheckBox);                            
                          }
                          break;
                      }
                  }
  
                  answerForm.x = 380;
                  answerForm.y = 200;
              }
  
              private function selectionHandler(event:MouseEvent):void {
                  Alert.show(event.currentTarget.toString());
              }
  
              private function resultHandler(event:ResultEvent):void {
                  questionArray = event.result as ArrayCollection;
  
                  txt1Questions.htmlText = questionArray.getItemAt(currentQuestionCounter).Question_Text;
                  questionType = questionArray.getItemAt(currentQuestionCounter).Question_Type;
                  btnNext.enabled = true;
                  CFCertService.returnAnswers(questionArray.getItemAt(currentQuestionCounter).Question_ID);
              }
  
              private function buttonEventHandler():void {
                  CFCertService.returnQuestions();
                  btnStartExam.enabled = false;
              }
  
              private function btnPrevEventHandler():void {
                  currentQuestionCounter--;
                  if (currentQuestionCounter == 0) {
                      btnPrev.enabled = false;
                  }
                  if (currentQuestionCounter &lt; questionArray.length) {
                      btnNext.enabled = true;
                  }
                  txt1Questions.htmlText = questionArray.getItemAt(currentQuestionCounter).Question_Text;
                  questionType = questionArray.getItemAt(currentQuestionCounter).Question_Type;
                  CFCertService.returnAnswers(questionArray.getItemAt(currentQuestionCounter).Question_ID);
  
              }
  
              private function answerReturnHandler(questionIndex:int):void {
              }
  
              private function btnNextEventHandler():void {
                  currentQuestionCounter++; 
  
                  if (currentQuestionCounter &gt; 0) {
                      btnPrev.enabled = true;
                  }
                  if (currentQuestionCounter &gt;= (questionArray.length - 1)) {
                      btnNext.enabled = false;
                  }
                  txt1Questions.htmlText = questionArray.getItemAt(currentQuestionCounter).Question_Text;
                  questionType = questionArray.getItemAt(currentQuestionCounter).Question_Type;
                  CFCertService.returnAnswers(questionArray.getItemAt(currentQuestionCounter).Question_ID);
  
              }
          ]]&gt;
      &lt;/fx:Script&gt;
  
      &lt;mx:Text id="txt1Questions" x="129" y="124"/&gt;
      &lt;s:Button id="btnStartExam" label="Start Exam" click="buttonEventHandler()" x="370" y="54"/&gt;
  
      &lt;mx:Form id="answerForm"/&gt;
      &lt;s:Button x="129" y="436" label="Previous" id="btnPrev" click="btnPrevEventHandler()" enabled="false"/&gt;
      &lt;s:Button x="642" y="436" label="Next" id="btnNext" click="btnNextEventHandler()" enabled="false"/&gt;
  
  &lt;/s:Application&gt;
  </code></pre>