tags:

views:

36

answers:

1

Hello everyone,

Please take a look at a segment of my Flex code:

<mx:Accordion id="accordian" width="100%" height="326" selectedIndex="0">
  <journal:ResearchJournalSection id="researchSection" width="100%"/>
  <journal:QuestionJournalSection id="questionSection" width="100%"/>
  <journal:DesignJournalSection id="designSection" width="100%"/>
</mx:Accordion>
<mx:Panel width="100%" height="129" layout="absolute" title="FAQ Area">
  <mx:Text x="0" y="10" text="What is a research question?&#xa;" width="250   

    height="20" fontWeight="bold"/>
 </mx:Panel>

what it does is showing three journals(Research,Question and Design),also showing a FAQ question panel beneath. Currently the FAQ Panel always shows "What is a research question",but I want to make it shown things that corresponding to what journal the user is currently selecting,so for example,if the user now clicks on "Design Journal",then the corresonding text in the FAQ area should read "What is importat about Design?".

Hope I make things clear,thanks in advance!

+2  A: 

My Flex is a little rusty, but you should be able to add an change="myFunction()" attribute on the Accordion pointing to an Actionscript function:

myFunction() {
  var selectedChild = accordian.selectedChild; //here 'accordian' is the id of your mx:Accordion
  if (selectedChild.id == 'researchSection') {
      myText.text = "What is a research question?"; //your mx:Text tag should have the id 'myText'
  } else if (selectedChild.id == 'questionSection') {
      myText.text = "What is a question question?"; //question question? that doesn't seem right; anyway you'll put something else here
  } else if (selectedChild.id == 'designSection') {
      myText.text = "What is a design question?";
  }
}

The function should be put in a script tag inside the mxml file.

Andrei Fierbinteanu
Thanks,Ander,I am new to Flex as well.Shall I put the myFunction directly in the mxml file where I created those journals ?Thx.
Robert
yes you can define script blocks using `<mx:Script><![CDATA[ some actionscript code here ]]></mx:Script>. Take a look at http://livedocs.adobe.com/flex/3/html/help.html?content=usingas_2.html for more details. Also I made some small corrections to the answer.
Andrei Fierbinteanu
Thanks a lot,Andrei,it works perfectly!I learned a lot,too
Robert