0 Replies Latest reply on Aug 2, 2011 1:52 PM by Mr Nitin

    how to change the data provider of the tree with the selection of combobox

    Mr Nitin

      This is my XML data in a file named `nodesAndStuff.xml`.

       

          <?xml version="1.0" encoding="utf-8"?>
          <root>
              <node label="One" />
              <node label="Two" />
              <node label="Three" />
              <node label="Four" />
              <node label="Five" />
              <node label="Six" />
              <node label="Seven" />
              <node label="Eight" />
              <node label="Nine" />
          </root>

      The component using this data source is an `XMLListCollection` which is bound to a spark `ComboBox` and the code for that is:

       

          <s:Application name="Spark_List_dataProvider_XML_test"
              xmlns:fx="http://ns.adobe.com/mxml/2009"
              xmlns:s="library://ns.adobe.com/flex/spark"
              xmlns:mx="library://ns.adobe.com/flex/halo"
              initialize="init();">

       

          <fx:Script>
              <![CDATA[
                  private function init():void {
                      xmlListColl.source = nodes.children();
                  }

      private function closeHandler(event:Event):void {
                      myLabel.text = "You selected: " +  ComboBox(event.target).selectedItem.label;                 myData.text = "Data: " +  ComboBox(event.target).selectedItem.data;
                  } 
              ]]>
          </fx:Script>

       

          <fx:Declarations>
              <fx:XML id="nodes" source="nodesAndStuff.xml" />
          </fx:Declarations>

       

          <mx:ComboBox id="cmbList" dataProvider="{ListXLC}" labelField="STOREVALUE"  close="closeHandler(event);"/>

           <s:dataProvider>
             
      <s:XMLListCollection id="xmlListColl" />
          
      </s:dataProvider>

      </mx:ComboBox>

      <mx:VBox width="250" color="0x000000">
                  <mx:Text  width="200" color="blue" text="Select a type of credit card."/>
                  <mx:Label id="myLabel" text="You selected:"/>
                  <mx:Label id="myData" text="Data:"/>
              </mx:VBox> 

       

      <mx:Tree id="myTree" width="50%" height="100%" visible="false" />


      </s:Application>

       

      now another of my xml for example this is one.xml

       

      <?xml version="1.0" encoding="utf-8"?>
      <root>
         
      <node label="Eleven" />
         
      <node label="Twelve" />
         
      <node label="Thirteen" />
         
      <node label="Fourteen" />
         
      <node label="Fifteen" />
         
      <node label="Sixteen" />
         
      <node label="Seventeen" />
         
      <node label="Eightteen" />
         
      <node label="Nineteen" />
      </root>

      and another one is two.xml

       

      <?xml version="1.0" encoding="utf-8"?>
      <root>
         
      <node label="twety one" />
         
      <node label="twety two" />
         
      <node label="twety three" />
         
      <node label="twety four" />
         
      <node label="twety five" />
         
      <node label="twety six" />
         
      <node label="twety seven" />
         
      <node label="twety eight" />
         
      <node label="twety nine" />
      </root>

       


      Now I have added my tree just below the list and I have saved counting from 10 to 19 in `one.xml`, 20 to 29 in `two.xml` and so on in different XML file. I have no clue how to connect the XML containing counting from 10 to 19 as the single node in tree at the selection of label one in list and make its visiblity true.this all are dependent on combobox as on selection of item in combobox will lead to change the dataprovider of tree at runtime. i.e on selecting value one in combobox one.xml should be the data provider for tree control. Can anyone help me on this