2012-12-12 6 views
1

나는 여러 가지 방법을 시도했지만 내 인생은 어떻게 생각할 수 없다. 기본적으로 나는 목록을 가지고있다. 목록의 항목을 선택하면 라디오 단추 레이블이 변경됩니다. 그러나 사용자가 라디오 버튼을 클릭했으면 레이블 및 텍스트 영역이 나타나기를 원합니다. 지금까지 코드 : - 어도비 플렉스 목록에서 라디오 버튼

<s:VGroup x="103" y="130" width="123" height="125"> 
    <s:RadioButton id="RadioButton1" label="{data.QuestionsRadioButton1}" groupName="QuestionsTestRadioButtons" click="RadioButton1_clickHandler(event)"/> 
    <s:RadioButton label="{data.QuestionsRadioButton2}" groupName="QuestionsTestRadioButtons" click="radiobutton1_clickHandler(event)" /> 
    <s:RadioButton id="RadioButton3" label="{data.QuestionsRadioButton3}" groupName="QuestionsTestRadioButtons" click="radiobutton2_clickHandler(event)"/> 
</s:VGroup> 

우리가 영원히 여기에있을 것 같은 나는 모든 코드를 게시하지 않습니다. 그러나 어쩌면 if 함수가 있을까요? 클릭 한 라디오 버튼이 실제로 옳은 대답인지 아닌지 말하기

어떤 제안이 가 감사합니다 도움이 될 것

+0

; 또는 라디오 버튼이 표시되는 방법 스택 오버플로에 대한 질문 답변으로 - 올바른 항목이 클릭되었는지 여부를 알고 있어야합니다. 그런 다음 Flex로 확장합니다. 프레임 워크는 어떻게 알 수 있습니까? 네가 말하지 않으면 안된다. 역동적 인 질문/답변이있는 경우; 어떻게 든 올바른 답을로드해야하며 선택한 답과 비교를 수행해야합니다. 아마도 "올바른"답변과 비교하기 위해 사용할 수있는 "값"을 라디오 버튼에 설정합니다. – JeffryHouser

답변

0

완전한 예를 초안 내 시도 :

Questionaire.mxml

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:local="*"> 
    <fx:Declarations> 
     <s:ArrayCollection id="questions"> 
      <local:Question text="It is raining …"> 
       <s:ArrayCollection> 
        <local:Answer text="Men"/> 
        <local:Answer text="Cats and dogs" correct="true"/> 
        <local:Answer text="Candy"/> 
       </s:ArrayCollection> 
      </local:Question> 
      <local:Question text="The sky is …"> 
       <s:ArrayCollection> 
        <local:Answer text="Blue" correct="true"/> 
        <local:Answer text="Orange" correct="true"/> 
        <local:Answer text="Grey" correct="true"/> 
        <local:Answer text="Green"/> 
       </s:ArrayCollection> 
      </local:Question> 
     </s:ArrayCollection> 
    </fx:Declarations> 

    <s:DataGroup dataProvider="{questions}" itemRenderer="QuestionRenderer"> 
     <s:layout> 
      <s:VerticalLayout gap="24"/> 
     </s:layout> 
    </s:DataGroup> 
</s:Application> 

을 QuestionRenderer.mxml

<?xml version="1.0" encoding="utf-8"?> 
<s:DataRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark"> 
    <fx:Script> 
     <![CDATA[ 
      [Bindable("dataChange")] 
      public function get question():Question { 
       return data as Question; 
      } 
     ]]> 
    </fx:Script> 

    <fx:Declarations> 
     <s:RadioButtonGroup id="answerGroup"/> 
    </fx:Declarations> 

    <s:layout> 
     <s:VerticalLayout/> 
    </s:layout> 

    <s:Label fontWeight="bold" text="{question.text}"/> 

    <s:DataGroup dataProvider="{question.answers}"> 
     <s:layout> 
      <s:HorizontalLayout/> 
     </s:layout> 
     <s:itemRenderer> 
      <fx:Component> 
       <s:DataRenderer> 
        <fx:Script> 
         <![CDATA[ 
          import spark.components.RadioButtonGroup; 

          public function get answerGroup():RadioButtonGroup { 
           return outerDocument.answerGroup; 
          } 
         ]]> 
        </fx:Script> 
        <s:RadioButton groupName="answerGroup" label="{data.text}" value="{data}"/> 
       </s:DataRenderer> 
      </fx:Component> 
     </s:itemRenderer> 
    </s:DataGroup> 

    <s:Label visible="{answerGroup.selectedValue}" text="This is {answerGroup.selectedValue.correct ? 'correct' : 'incorrect'}."/> 
</s:DataRenderer> 

Question.as

package { 
    import mx.collections.ArrayCollection; 

    [Bindable] 
    [DefaultProperty("answers")] 
    public class Question { 
     public var text:String; 
     public var answers:ArrayCollection; 
    } 
} 

Answer.as 데이터 구조를 모른 채

package { 
    [Bindable] 
    public class Answer { 
     public var text:String; 
     public var correct:Boolean = false; 
    } 
} 
관련 문제