2 Replies Latest reply on Dec 3, 2007 7:10 AM by JSFL_monkey

    Help using dynamic XML with Tree Menu

    JSFL_monkey
      Can some one please help me? I don't know what I'm doing wrong. I'd simply like to be able to load an XML file of data and use this data to populate a Flex tree component.
      The XML file needs to reside on the server and will change from time to time, so I am loading it via an HTTPService call. The part that I can't get to work is the way the
      XML is displayed in the Tree component. It ends up blank or sometimes I just get the result of "[object Object]". I know my syntax must be screwed up somewhere, but because
      AS3 and Flex are new territory for me, I can't get it to work. I am feeling my IQ drop on a minute to minute basis. Please help me if you can! Thanks!

      In this example, I am expecting a list of the different groceries/categories to show up in the tree menu. Instead, I get nothing.

      ------------------------------------------------------------------------------------------ ---
      HERE IS THE XML FILE, CALLED "groceries.xml":

      <catalog>
      <category name="Meat">
      <product name="Buffalo" cost="4" isOrganic="No" isLowFat="Yes"/>
      <product name="T Bone Steak" cost="6" isOrganic="No" isLowFat="No"/>
      <product name="Whole Chicken" cost="1.5" isOrganic="Yes" isLowFat="No"/>
      </category>
      <category name="Vegetables">
      <product name="Broccoli" cost="2.16" isOrganic="Yes" isLowFat="Yes"/>
      <product name="Vine Ripened Tomatoes" cost="1.69" isOrganic="No" isLowFat="Yes"/>
      <product name="Yellow Peppers" cost="1.25" isOrganic="Yes" isLowFat="Yes"/>
      </category>
      <category name="Fruit">
      <product name="Bananas" cost="0.95" isOrganic="Yes" isLowFat="Yes"/>
      <product name="Grapes" cost="1.34" isOrganic="No" isLowFat="Yes" />
      <product name="Strawberries" cost="2.5" isOrganic="Yes" isLowFat="Yes"/>
      </category>
      </catalog>

      ------------------------------------------------------------------------------------------ ---

      ------------------------------------------------------------------------------------------ ---
      HERE IS THE MXML FLEX FILE THAT ISN'T WORKING AS I'D LIKE IT TO:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" initialize="initializeHandler(event)" width="240" height="340">
      <mx:Script>
      <![CDATA[
      import mx.collections.XMLListCollection;
      import mx.collections.ICollectionView;
      import mx.controls.List;

      private function initializeHandler(event:Event):void {
      textService.send();
      }

      private function resultHandler(event:Event):void {
      myTree.dataProvider = textService.lastResult.catalog;
      }
      ]]>
      </mx:Script>

      <mx:HTTPService id="textService" url="groceries.xml" result="resultHandler(event)" />
      <mx:Tree id="myTree" labelField="@name" showRoot="false" x="20" y="20" width="200" height="300" />
      </mx:Application>
      ------------------------------------------------------------------------------------------ ---

      Any help is deeply appreciated.