1 Reply Latest reply on Apr 14, 2008 7:47 AM by Philippo

    XML and ResultEvent parsing

    Philippo
      I have the following XML created by a PHP file:

      <output>
      <projects>
      <project id="1" name="SL Recruitment"/>
      </projects>
      <taskLists>
      <taskList id="1" name="Iteration 1"/>
      </taskLists>
      </output>

      I have set up a handler function that will grab the result event and parse the XML. The code looks something like this:

      httpService.addEventListener(ResultEvent.RESULT, resultHandler);
      httpService.send();

      private function resultHandler(event:ResultEvent):void
      {
      Alert.show(event.result.output.projects.project);
      Alert.show(event.result.output.taskLists.taskList);
      }

      The strange thing is that the first Alert call works and [object][object] is displayed, and I can parse that data and put it into an ArrayCollection object. However, the second Alert call cannot seem to find event.result.output.taskLists.taskList, and returns the following error:

      TypeError:Error 1010: A term is undefined and has no properties

      Seems Flex cannot find the 'taskLlists' element in the XML file and is returning a null object.

      Any idea what may be wrong? Why am I only able to access the first element in the XML file, but not the second element? Am I missing something? I just can't figure out what I am doing wrong here. Help!

      Thanks!
        • 1. Re: XML and ResultEvent parsing
          Philippo Level 1
          Never mind, managed to figure it out. It appears that there was something wrong with the PHP script and it was outputing the wrong XML code.

          Just for future reference so I can avoid these stupid mistakes, does anybody know how I can use Alert.show to view the contents of the ResultEvent object? I've tried using:

          Alert.show(event.result.toString());
          Alert.show(event.result.output.toString();
          Alert.show(event.result);

          But all of these simply display the text "[object Object]". How can I view the actual contents of the resultEvent object? I want to be able to see something like this in the alert window:

          <output>
          <projects>
          <project id="1" name="SL Recruitment"/>
          </projects>
          <taskLists>
          <taskList id="1" name="Iteration 1"/>
          </taskLists>
          </output>

          This would really make debugging much easier.