1 Reply Latest reply on May 7, 2007 11:27 AM by KomputerMan.com

    XML data in Flex

    KomputerMan.com Level 1
      I am passing in some XML data from a CFC, works fine... Well at I can see the data in debug mode but the data doesn't work like it does if the data gets built in Flex itself. I am pulling in the XML data to work with the "3 State CheckBox Tree" control that can be downloaded from the Flex Developers Exchange.

      If the XML is created in the Flex code itself the control works fine. Here is how the XML data is created in Flex:

      [Bindable]
      public var folderList:XMLList =
      <>
      <folder state="schrodinger" label="Marketing Collateral" isBranch="true" >
      <folder state="schrodinger" isBranch="true" label="Media, PR, and Communications" >
      <folder state="unchecked" isBranch="false" label="Article Reprint Disclaimers" />
      <folder state="unchecked" isBranch="false" label="Articles Reprints" />
      <folder state="unchecked" isBranch="false" label="Interviews and Transcripts" />
      <folder state="unchecked" isBranch="false" label="Press Kits" />
      <folder state="unchecked" isBranch="false" label="Press Releases" />
      <folder state="unchecked" isBranch="false" label="Quick Hits" />
      <folder state="unchecked" isBranch="false" label="Rep Talking Points" />
      <folder state="unchecked" isBranch="false" label="Special Updates" />
      <folder state="checked" isBranch="false" label="White Papers" />
      </folder>
      <folder state="schrodinger" isBranch="true" label="Forms and Applications" >
      <folder state="unchecked" isBranch="false" label="Applications" />
      <folder state="checked" isBranch="false" label="Forms" />
      </folder>
      </folder>
      </>;

      [Bindable]
      public var folderCollection:XMLListCollection;

      private function init() : void{
      folderCollection = new XMLListCollection(folderList);
      checkTree.dataProvider = folderCollection;
      }


      If I pause the application and look at the data in debug mode I see that the contents of the folderCollection XMLListCollectionList looks like this picture: CLICK HERE TO SEE THE XML DATA XML Data built in Flex

      When I pass the data into Flex using a CFC it comes in as an XMLList object. So I convert it into an XMLListCollection and pass it to the component. Here is the code I use to do that, minus the call to the CFC...

      <?xml version="1.0" encoding="iso-8859-1"?>
      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" height="100%" width="100%" creationComplete="init()" >

      <mx:Script>
      <![CDATA[

      import mx.collections.*;
      import datamodels.allowedTablesModel;
      import util.CheckTreeRenderer;
      import events.allowedTableEvent;

      [Bindable]
      public var allTablesList_1:XMLList;

      [Bindable]
      public var folderCollection:XMLListCollection;

      private function init() : void{
      folderCollection = new XMLListCollection(allTablesList_1);
      checkTree.dataProvider = folderCollection;
      }


      private function modTables():void
      {
      modButton.visible=true;
      // Used to pause the applet so I can look at the data
      }

      ]]>
      </mx:Script>
      <mx:Tree id="checkTree" itemRenderer="util.CheckTreeRenderer" labelField="label" width="100%" height="100%" />

      <mx:Button id="modButton" fontFamily="Arial" fontSize="10" fontWeight="bold" click="modTables()"
      label="Modify Tables" visible="true" x="553.5" y="428" width="125"/>

      </mx:Canvas>


      If I pass the data in from a CFC the data looks like the folowwing picture when I pause it in Flex.
      CLICK HERE TO SEE THE DATA PASSED IN FROM A CFC

      I can't see why the component works if I build the data in the applet verses passing it in via an XML feed. Any ideas???

      Have an Ordinary Day...
      KomputerMan ~|:-)

        • 1. Re: XML data in Flex
          KomputerMan.com Level 1
          From Adobe Support...

          "When you use an XML-based data provider with a tree you must specify the label field, even if it is "label". The XML object includes the root, so you must set showRoot="false". Remember that the Tree will not, by default, reflect dynamic changes to the XML object."

          So all I had to do was change the component tag from this:
          <mx:Tree id="checkTree" itemRenderer="util.CheckTreeRenderer" labelField="label" width="100%" height="100%" />


          to this:
          <mx:Tree id="checkTree" itemRenderer="util.CheckTreeRenderer" showRoot="false" labelField="@label" width="100%" height="100%" />

          Just as an FYI... The Adobe support is worth the cost if you are fairly new to Flex. I have been flexing for about 9 months now and find their service invaluable!!!

          Have an Ordinary Day...
          KomputerMan ~|:-)