0 Replies Latest reply on Nov 30, 2009 2:16 PM by ekotval

    Need help creating a survey

    ekotval

      So I'm trying to create a survey in flex and I'm having some problems.

      It's supposed to be a 50 question survey that will total the values of your answer and display them when you're done. I'm trying to access the values of the radiobuttongroups in the different states, but I can't figure out a way to make it work. Can anyone help me?

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" currentState="state1">
          <mx:Script>
              <![CDATA[
             
                  import flash.events.Event;
                 
                 
                  private function handleValues(event:Event):void{
                      //Handle Multiple Values
                      var i:int;
                      var charlie:String = new String();
                      var oscar:String = new String();
                      var mike:int;
                      var total:int;
                     
                      for(i = 1; i <= 2; i++){
                          oscar = "answer" + i;
                          charlie = "state" + i;
                          mike = this[charlie].this[oscar].selectedValue.toString();
                          total = total + mike;
                          trace(oscar);
                          trace(mike);
                      }
                     
                      answerlabel.text = total.toString();
                     
                  }
                 
                 
                     
              ]]>
          </mx:Script>
         
          <mx:states>
              <mx:State name="state1">
                  <mx:AddChild position="lastChild">
                      <mx:RadioButtonGroup id="answer1"/>
                  </mx:AddChild>
                  <mx:AddChild position="lastChild">
                      <mx:RadioButton x="191" y="270" label="Button 1" groupName="answer1" value="1"/>
                  </mx:AddChild>
                  <mx:AddChild position="lastChild">
                      <mx:RadioButton x="191" y="296" label="Button 2" groupName="answer1" value="2"/>
                  </mx:AddChild>
                  <mx:AddChild position="lastChild">
                      <mx:Button x="489" y="447" label="next" id="nextbutton" click="currentState='state2'"/>
                  </mx:AddChild>
              </mx:State>
              <mx:State name="state2">
                  <mx:AddChild position="lastChild">
                      <mx:RadioButtonGroup id="answer2"/>
                  </mx:AddChild>
                  <mx:AddChild position="lastChild">
                      <mx:RadioButton x="451" y="303" label="Button 1" groupName="answer2" value="1"/>
                  </mx:AddChild>
                  <mx:AddChild position="lastChild">
                      <mx:RadioButton x="451" y="329" label="Button 2" groupName="answer2" value="2"/>
                  </mx:AddChild>
                  <mx:AddChild position="lastChild">
                      <mx:Button x="128" y="427" label="prev" id="prevbutton" click="currentState='state1'"/>
                  </mx:AddChild>
                  <mx:AddChild position="lastChild">
                      <mx:Button x="472" y="427" label="submit" id="submitbutton" click="handleValues(event); currentState='state3'"/>
                  </mx:AddChild>
              </mx:State>
              <mx:State name="state3">
                  <mx:AddChild position="lastChild">
                      <mx:Label x="313" y="291" text="Label" id="answerlabel"/>
                  </mx:AddChild>
                  <mx:AddChild position="lastChild">
                      <mx:Button x="300" y="386" label="again?" id="startover" click="currentState='state1'"/>
                  </mx:AddChild>
              </mx:State>
          </mx:states>
         
         
      </mx:Application>