3 Replies Latest reply on Feb 18, 2008 5:24 AM by peterent

    DateChooser returning value/text from xml

    Tobias Bergström
      Im a beginner with Flex.

      How do I connect an external xml to a DateChooser so every time a date is picked a value/or text (different for different dates) from the xml is passed into a textArea.

      Greatful is this could be shown with the entire code since I'm rather new to this.

      Thanks in advance!
        • 1. Re: DateChooser returning value/text from xml
          peterent Level 2
          Each time a date is picked on the DateChooser an "change" event is dispatched. By having a function handle the change event, the function can extract the information from the XML and move it to the TextArea.

          <mx:DateChooser change="handleDatePick(event)" />
          <mx:TextArea id="output" />

          I'm going to assume your XML data is in a variable called "xmldata"; you'll have to figure out how to populate it.

          The following code goes into a <mx:Script> block in your MXML file:

          private function handleDatePick( event:Event ) : void
          var chooser:DateChooser = event.target as DateChooser; // just to make it easier to understand the code
          var d:Date = chooser.selectedDate; // the date the user picked. becareful, it can be null if the person picks the date already selected
          if( d == null ) return;
          var node:XML = xmldata..(@date == d.toDateString()); // this will take some explanation below
          output.text = node.value; // the item in the XML node you want to see in the TextArea
          } // done

          OK, Let's assume your XML data looks like this:

          <node date="Thu Jan 31 2008"><value>This is a test</value></node>
          <node date="Thu Feb 14 2008"><value>This is Valentine's Day</value></node>

          So each <node> in the XML has a date attribute. In the statement above (@date == d.toDateString()) will select the <node> which has a date that matches the formatted date selected by the user. If the user picked Feb 14, 2008, the d.toDateString() should match it.

          Keep in mind that the user might select a date that doesn't match anything in your XML.

          That's the idea. I can't put in any more detail because I don't know what your XML looks like. If your date isn't in a format that the Date format functions produce, you can use the <mx:DateFormatter> to make a value you can use for comparison.
          • 2. Re: DateChooser returning value/text from xml
            Tobias Bergström Level 1
            Hi Peter,
            This was exactly the beautiful sollution I was looking for. Thanks! However I feel really emberresed cause I can't figure out how to populate it.
            I have succeeded to populate DataGrids through HttpService but that's because I found complete code examples on how to do it... To populate the it through a external xml that is called with HttpService would be the the preferable way as I see it.

            A Question: I will probably buy a support program. Which program do I need (gold or platinum)? (I, one person, want to learn the program on a basic level and pass the hurtles as quick as possible with code examples). Are you working at the support?

            Best regards, Tobias
            • 3. Re: DateChooser returning value/text from xml
              peterent Level 2
              We have a number of different plans. This one is probably more suitable to your needs:

              But click this link has them all: http://www.adobe.com/support/programs/

              Good luck.