5 Replies Latest reply on May 2, 2008 6:26 AM by LeslieInNC

    Populating Tree with External XML File

    LeslieInNC
      I want to use external files for populating Flex 3 components. I have been successful using code very similar to that below for a data grid & for a combo box, but it won't work for a tree. Can you determine wh?

      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:HTTPService id="dp_Tree1" url="Tree1.xml" />
      <mx:Tree dataProvider="{dp_Tree1.lastResult.root.node}" creationComplete="dp_Tree1.send()" width="333"/>
      </mx:WindowedApplication>

      It's not working & I can't determine why. Attached is my xml file that I tested it with.

        • 1. Populating Tree with External XML File
          GavinCroy
          Try setting a returnType="e4x" on your HTTPService and changing your query to: dataProvider="{dp_Tree1.lastResult.node}". I guess you could also play it safe by also adding labelField="@label" to your tree definition as well...

          Edit: When I come across this kind of problem I tend to add a resultHandler event handler to the service, then use the debugger to check that the XML has been put into the result property as I expected..
          • 2. Re: Populating Tree with External XML File
            LeslieInNC Level 1
            Gavin,

            I tried the code you suggested (using "resultFormat" instead of "returnType" which could not be resolved), but no tree appeared. No error, but no tree.

            I don't know how to put a to add a resultHandler event handler to the service, then use the debugger to check the XML result. If you know of a good example of that, please point me that way!
            • 3. Re: Populating Tree with External XML File
              ntsiii Level 3
              Here is some exmple code.
              Tracy
              • 4. Re: Populating Tree with External XML File
                ntsiii Level 3
                this is for DataGrid, but Tree is even simpler. Just change the XMLListCollection var to a plain XML var, say _xmlResult, and then:
                _xmlResult = XML(event.result);

                Use that var in the Tree dataProvider:
                dataProvider="{_xmlResult}";

                Tracy
                • 5. Re: Populating Tree with External XML File
                  LeslieInNC Level 1
                  Thanks a bunch folks, but my intent is to have as little code as possible. I want to help people who are not coders create designs using external xml files to populate controls. I was able to create very simple code with just two lines to populate a DataGrid from an external xml file:

                  <mx:HTTPService id="dp_DataGrid1" url="DataGrid1.xml" />
                  <mx:DataGrid dataProvider="{dp_DataGrid1.lastResult.component.rows}" creationComplete="dp_DataGrid1.send()" />

                  And just two lines for a ComboBox:

                  <mx:HTTPService id="dp_ComboBox1" url="ComboBox1.xml" />
                  <mx:ComboBox dataProvider="{dp_ComboBox1.lastResult.component.rows}" creationComplete="dp_ComboBox1.send()" />

                  Isn't it possible to populate a tree with two lines like as it is with a DataGrid & ComboBox?