3 Replies Latest reply on Aug 5, 2006 5:46 AM by BaniR

    Populate Tree with external XML

      HI every one.
      I'm trying to populate a tree controller from an external XML

      this is the code i use but something goes wrong
      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" height="400">

      import mx.collections.XMLListCollection;
      import mx.collections.ArrayCollection;

      // An XML object with categorized produce.
      var myXML:XML = new XML();
      var XML_URL:String = "assets/menu.xml";
      var myXMLURL:URLRequest = new URLRequest(XML_URL);
      var myLoader:URLLoader = new URLLoader(myXMLURL);
      myLoader.addEventListener("complete", xmlLoaded);

      function xmlLoaded(evtObj:Event) {
      myXML = XML(myLoader.data);
      trace("Data loaded.");


      <mx:Tree id="prodTree" dataProvider="{myXML}" width="200"
      showRoot="false" labelField="@label"/>


      And thi is the XML file.......
      <?xml version="1.0"? format="e4x">
      <menu label="Menü 1bani" aktion="message" variables="Menü 1 Text...">
      <submenu label="Untermenü">
      <eintrag label="Eintrag"/>
      <eintrag label="Eintrag"/>
      <eintrag label="Eintrag"/>
      <submenu label="Untermenü">
      <eintrag label="Eintrag"/>
      <eintrag label="Eintrag"/>
      <eintrag label="Eintrag"/>
      <menu label="Menü 2">
      <eintrag label="Eintrag"/>
      <eintrag label="Eintrag"/>
      <eintrag label="Eintrag"/>
      <menu label="Menü 3">
      <submenu label="Untermenü">
      <eintrag label="Teil 1.1" aktion="message" variables="Teil 1.1"/>
      <eintrag label="Teil 1.2" aktion="message" variables="Teil 1.2"/>
      <eintrag label="Teil 1.3" aktion="message" variables="Teil 1.3"/>
      <submenu label="Untermenü">
      <submenu label="Teil 2.1" aktion="message" variables="Teil 2.1">
      <eintrag label="Teil 2.1.1" aktion="message" variables="Teil 2.1.1"/>
      <eintrag label="Teil 2.1.2" aktion="message" variables="Teil 2.1.2"/>
      <eintrag label="Teil 2.1.3" aktion="message" variables="Teil 2.1.3"/>
      <eintrag label="Teil 2.2" aktion="message" variables="Teil 2.2"/>
      <eintrag label="Teil 2.3" aktion="message" variables="Teil 2.3"/>
      <eintrag label="Eintrag"/>
      <menu label="Menüs">
      <eintrag label="Hauptmenü" aktion="newMenu" variables="menu1.xml"/>
      <eintrag label="Links" aktion="newMenu" variables="menu2.xml"/>
      <eintrag label="Nachrichten" aktion="newMenu" variables="menu3.xml"/>

      i tried the xml internaly and it worked.
      where is the difference betwen an external XML and an internal one.
      can anybody please tell me what is wrong or what else can i do in this case.
      Thanks in advance
        • 1. Re: Populate Tree with external XML
          Josh Johnson
          If you're trying to reference an external file, wouldn't it be easier to just have:

          <mx:XML id="myXML" source="assets/menu.xml" />

          <mx:Tree id="prodTree" dataProvider="{myXML}" width="200"
          showRoot="false" labelField="@label"/>
          • 2. Re: Populate Tree with external XML
            ntsiii Level 3
            First, isolate the problem.

            Are you getting the xml into Flex?

            If not, try Josh's method. Understand that that is compile time operation. another possibility is HTTPService, my personal favorite.

            If so, post back

            • 3. Re: Populate Tree with external XML
              BaniR Level 1
              First of all thnx for your help.
              I tried the HTTP service but when i publish the Tree controller shows only a top node wich says [object HTTPService] and it doesn't interprets the XML. Where is the problem?

              I triedn also the <mx:XML source="assets/menu.xml"> and it worked fine
              but since I'm building an application who interacts with PHP i'm gona have to use the HTTPService.