1 Reply Latest reply on Dec 8, 2006 5:48 AM by peterent

    Creating a <mx:Tree>

    wy790289 Level 1

      I would like to create a program to show a directory in server for users to select a file from a tree object. I use PHP program to create a XML which format will be something like:

      <?xml version="1.0" encoding="utf-8">
      <rootdir name="/">
      <dir name="dir1">
      <file name="file1" />
      <file name="file2" />
      <file name="file3" />
      <file name="file4" />

      In my mxml program I use a mx:HTTPService (e.g. id="httpservice") to get the above XML and create a mx:XMLLISTCollection (e.g. id="xlistc") with source='{httpservice.lastResult.root}". And also the dataProvider of the mx:Tree is set to "xlistc".

      However the tree could not display anything. Do I create the mx:Tree incorrectly?

        • 1. Re: Creating a &lt;mx:Tree&gt;
          peterent Level 2
          First, set your tree like this: <mx:Tree dataProvider="{httpservice.lastResult.rootdir}" ... />

          Note that I didn't use root, but rootdir. The <root> node IS httpservice.lastResult, it is not a child of it; <rootdir> is that child.

          Second, your XML has different nodenames (dir, file) and the Tree really likes all the nodenames to be the same. To use your XML data you'll need a labelFunction to provide the correct value for display:

          <mx:Tree dataProvider="{httpservice.lastResult.rootdir}" labelFunction="displayNodeName" labelField="@name" />

          In a Script block:

          private function displayNodeName( item:Object ) : String {
          var node:XML = XML(item);
          return node.@name;

          This may seem silly, but I believe it is necessary to have the labelFunction when the nodenames are inconsistant even when labelField is specified.