3 Replies Latest reply on Aug 27, 2009 12:28 PM by wolfman33

    How to populate a tree from .aspx file?

    starbabu

      Hi,

       

      I'm very new to flex. I have a .aspx file which has xml populated in it. I would like to populate the tree based on the values of the .aspx file. Here is my code which i have tried doing this functionality but it couldn't worked out. Could anyone help me out to resolve this problem.

      This is my sample aspx file:

       

      Sample.aspx:

      <?xml version="1.0" encoding="utf-8"?>

      <myTree label="Main Root">

      <node label="Root">

      <node label="Folder a">

      <node label="item 1 a"/>

      </node>

      <node label="Folder b">

      <node label="item 1 b"/>

      <node label="item 2 b"/>

      </node>

      <node label="Folder c">

      <node label="item 1 c"/>

      <node label="item 2 c"/>

      </node>

      <node label="Folder d">

      <node label="item 1 d"/>

      <node label="item 2 d"/>

      </node>

      </node>

      </myTree>

       

      Here is my mxml file which i was trying:

       

      TreefromXml.mxml:

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application

       

       

      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="XmlRpc.send()"

      >

       

      <mx:Script>

      <![CDATA[

       

      import

      mx.collections.ArrayCollection;

       

      import

      mx.rpc.events.FaultEvent;

       

      import

      mx.rpc.events.ResultEvent;

       

      import

      mx.controls.Alert;

       

      public var XmlNode:XML=new

      XML();

       

      public function HandleXml(event:ResultEvent):

      void

      {

       

      XmlNode= new XML(event.result.myTree.node);

       

       

      tree1.dataProvider=event.result.myTree.node;

       

       

       

       

      }

       

      public function HandleFault(event:FaultEvent):

      void

      {

      Alert.show(event.fault.faultString, "Error"

      );

      }

      ]]>

       

      </mx:Script>

       

       

      <mx:HTTPService id="XmlRpc" url="Sample.aspx" result="HandleXml(event)" fault="HandleFault(event)">

       

      </mx:HTTPService>

       

      <mx:Panel id="panel1" width="400" height="200">

       

      <mx:Label id="label1" text="Sample Label" />

       

      <mx:Tree id="tree1" labelField="@label">

       

       

      </mx:Tree>

       

       

      </mx:Panel>