3 Replies Latest reply on Jun 13, 2007 5:05 AM by silverrider

    Tree dataProvider from PHP

      Hello all!
      I see in the web many many many example how to populate a Tree, but, i cant find no example how to populate a Tree FROM PHP.
      I am using HTTPService and know how to use it but, i don't know the structure of nodes.
      In PHP file, i am doing this:
      echo "<node label='root'><node label='NODE 1'><node label='child 1 of NODE 1' /><node label='child 2 of NODE 1' /></node></node>";
      and, in the Tree, I am putting: dataProvider="{myHttpService.lastResult}"
      but, nothing happens, no result in Tree!
      What is the correct way?
        • 1. Re: Tree dataProvider from PHP
          Hi - I had exactly the same problem and it took a while to figure out but here is what i did. First you must get your xml organised properly. Here is part of my php file that got my xml together…

          $outputColumns .= "<data>";
          while ($row = mysql_fetch_array($resultColumns)) //returns data row by row as an array

          $outputColumns .= "<row label = 'row $colNumber'>";
          for($j=0;$j < $numberoffields;$j++)//loop for number of columns
          //go to first column $j and then get name and then tag it
          //then move on and change column name
          $cName = mysql_field_name($resultColumns, $j);

          $outputColumns .="<$cName label = '$cName'>"; //wrap it up as a tag
          $outputColumns .= $row[$cName]; //add current row/column value
          $outputColumns .= "</$cName>"; //finish tagging column name
          $outputColumns .= "</row>";

          $outputColumns .= "</data>";

          Then i had issues getting the tree to recognise the data properly - finally i realised i had to use the labelField attribute and then use @label…

          <mx:Tree id="myTree" labelField="@label"
          width="190" height="100%" borderThickness="1" borderColor="#362d97" backgroundColor="#1a1752" backgroundAlpha="0.27"/>


          Hope this helps

          • 2. Re: Tree dataProvider from PHP
            I've got my list populating correctly from XML generated by php but any time I click on a folder in the tree list I get an error:

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="dirListSvc.send();">
            import mx.controls.Alert;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            private var dirList:XML;
            public var selectedNode:XML;

            // Event handler for the Tree control change event.
            public function treeChanged(event:Event):void {
            selectedNode=Tree(event.target).selectedItem as XML;
            private function directoryResultHandler(event:ResultEvent):void

            dirList = event.result as XML;

            // Fault handler - displays the error
            private function directoryFaultHandler(event:FaultEvent):void

            Alert.show(event.fault.message, "Could not load dirList");



            url=" http://localhost/iqAssets/scripts/directory.php"

            <mx:HDividedBox width="100%" height="100%">
            <mx:Tree x="10" y="10" labelField="@label" dataProvider="{dirList}" width="250" height="530" change="treeChanged(event)"/>
            <mx:Panel height="100%" width="50%" title="{selectedNode.@label}">
            <mx:Text text="{selectedNode.@path}" />
            <mx:Image source="{selectedNode.@path}" />
            • 3. Re: Tree dataProvider from PHP
              silverrider Level 1
              Well - one main difference i see is that i return objects - i do not use e4X…

              <mx:HTTPService id=""
              url=" http://myurl.php"
              resultFormat="object" >