0 Replies Latest reply on Dec 25, 2010 8:35 AM by bindu naveen 4974

    Questions are binding but unable to bind answers

    bindu naveen 4974

      <mx:Script>

      <![CDATA[

      import flash.net.navigateToURL;

       

      import mx.controls.Alert;

      import mx.events.CloseEvent;

      import mx.events.ItemClickEvent;

      import mx.rpc.events.FaultEvent;

      import mx.rpc.events.ResultEvent;

       

      [Bindable]

      public var score:Number=0.0;

      import mx.collections.ArrayCollection;

      import mx.core.Application;

      import mx.events.FlexEvent;

       

      [Bindable]

      public var quizQuestions:XML;

      public var ansData:Object;

      [Bindable]

      private var currQuesNo:int = 0;

      [Bindable]

      private var questionsList:ArrayCollection;

      [Bindable]

      private var question:Object;

      [Bindable]

      public var len:Number;

      [Bindable]private var rb:RadioButton;

      [Bindable]private var rbg:RadioButtonGroup;

      [Bindable]private var rbg1:RadioButtonGroup;

      [Bindable]

      public var count:int=0;

      [Bindable]

      public var currQuesId:Number;

      /* public var ansData:Object; */

      public var resultArr:Array=new Array();

       

       

      protected function titlewindow1_closeHandler(event:CloseEvent):void

      {

      }

      private function init():void {

      currQuesId = 1;

       

      }

      protected function next_clickHandler(event:MouseEvent):void

      {

      if(isNaN(currQuesId))

      {

      currQuesId=1;

      }

      else if(currQuesId>=len)

      {

      currQuesId=len;

      }

      else

      {

      currQuesId++;

      }

      if(count!=len)

      {

      count++;

      quesText.text=quizQuestions.question[count].@value;

      quesNum.text="Question"+(count+1)+"of"+len;

       

      ansBox.removeAllChildren();

      rbg=new RadioButtonGroup();

      rbg.addEventListener(ItemClickEvent.ITEM_CLICK,check);

       

      for each(var answer:XML in quizQuestions.quesion[count].answer)

      {

      rb=new RadioButton();

      rb.group=rbg;

      rb.id=quesNum.text;

      rb.label=answer;

      if(resultArr[currQuesId])

      if(rb.label==resultArr[currQuesId].selectedValue)

      {

      rb.selected=true;

      }

      next.visible=true;

       

      }

      ansBox.addChild(rb);

      }

       

       

      /* if(currQuesId>len)

      {

      next.visible=false;

      }  */

      }

      private function check(e:Event):void

      {

      var rbg:RadioButtonGroup=e.target as RadioButtonGroup;

       

      ansData=new Object();

      ansData.selectedValue=rbg.selectedValue;

      ansData.quesText=quesText.text;

      resultArr[currQuesId]=ansData;

      next.visible=true;

      if(currQuesId==len)

      {

      next.visible=false;

      }

       

       

      }

       

      protected function quizLoader_resultHandler(event:ResultEvent):void

      {

      quizQuestions=event.result as XML;

      len=quizQuestions.question.length();

      }

       

       

      protected function quizLoader_faultHandler(event:FaultEvent):void

      {

       

      Alert.show(event.fault.message, "Could not load data");

       

      }

       

      ]]>

      </mx:Script>

       

      <mx:HTTPService id="quizLoader"

      url="C:\Users\Bindu\Adobe Flash Builder 4\test\QuizPrototype\src\assets\xml\quiz.xml" useProxy="false" method="POST"

      resultFormat="e4x"

      result="quizLoader_resultHandler(event)"

      fault="quizLoader_faultHandler(event)"/>

       

      <mx:Label id="quesNum" text="Question 1 of {len}"/>

       

      <mx:TextArea id="quesText" text="{quizQuestions.question[0].@value}" editable="false" width="90%" height="100"/>

      <mx:VBox id="ansBox" paddingLeft="10" paddingRight="10"

      paddingBottom="10" paddingTop="10" 

      borderThickness="1" borderStyle="solid"

      borderColor="#CCCCCC" width="551">

      <mx:RadioButtonGroup id="frb" itemClick="check(event);"/>

      <mx:RadioButton groupName="frb" id="r1" label="Red"/>

      <mx:RadioButton groupName="frb" id="r2" label="Green"/>

      <mx:RadioButton groupName="frb" id="r3" label="Blue"/>

      <mx:RadioButton groupName="frb" id="r4" label="white"/>

       

      </mx:VBox>

      <mx:ControlBar>

      <mx:Button id="next" label="Next Question" click="next_clickHandler(event)"  width="106" visible="false"/>

      </mx:ControlBar>

       

       

      xml file

       

      <?xml version="1.0" encoding="utf-8"?>

      <questions>

      <question id="1" value="What is the sky colour?" ans="Blue">

      <answer id='1' value="Red"/>

      <answer id='2' value="Green"/>

      <answer id='3' value="Blue"/>

      <answer id='4' value="white"/>

      </question>

      <question id="2" value="Which one is a Machine?" ans="computer">

      <answer id='1' value="computer"/>

      <answer id='2' value="plate"/>

      <answer id='3' value="bottle"/>

      <answer id='4' value="Chilli"/>

      </question>

      <question id="3" value="Whats your eye color?" ans="Black">

      <answer id='1' value="Red"/>

      <answer id='2' value="Black"/>

      <answer id='3' value="Blue"/>

      <answer id='4' value="Pink"/>

      </question>

      </questions>

      output
      1.png

      1.png

       

      and if I click next question button...it is showing the question but it is not showing the answers.

      What might be the problem?