2 Replies Latest reply on Sep 30, 2006 5:44 PM by walkthenose

    ComboBox to Load New XML file

    walkthenose
      I have an XML file containing a node with a reference to another XML file. I am trying to load the first XML file into a ComboBox. When the user makes a selection, the new XML file will load into a TileList/VBox. I cannot figure out how to pass the XML file referenced from the user's selection and display the results of that new XML file .

      So this is the flow:

      1. User chooses the catalog they would like to view from a CombBox (which is populated by an XML file)
      2 The Catagories referenced in #1 additionally point to another .xml file
      3. The user chooses from the ComboBox
      4. The appropriate XML file is passed and displayed in a TileList/VBox

      i hope i am making sense...
        • 1. Re: ComboBox to Load New XML file
          mike_morearty Level 1
          Do you mean something like this:

          --- Main file: ---

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="loadNewCategory(category.selectedItem)">
          <mx:Label x="10" y="10" text="Pick a category of products to browse:"/>
          <mx:ComboBox dataProvider="{categoryData.category}" labelField="@name" x="245" y="8" width="140" id="category" change="loadNewCategory(category.selectedItem)"></mx:ComboBox>
          <mx:Label x="10" y="36" text="Products in the '{category.selectedItem.@name}' category:"/>
          <mx:List x="10" y="62" width="375" height="271" dataProvider="{productData.product}" labelField="@name"></mx:List>

          <mx:XML id="categoryData" source="categories.xml" />

          <mx:Script>
          <![CDATA[
          [Bindable]
          public var productData:XML;

          private function loadNewCategory(category:Object):void
          {
          var loader:URLLoader = new URLLoader(new URLRequest(category.@file));
          loader.addEventListener(Event.COMPLETE, function(e:Event):void
          {
          productData = XML(loader.data);
          });
          }
          ]]>
          </mx:Script>
          </mx:Application>

          --- categories.xml: ---

          <?xml version="1.0" ?>
          <categories>
          <category name="cheap" file="cheap.xml" />
          <category name="cool" file="cool.xml" />
          <category name="fast" file="fast.xml" />
          </categories>

          --- cheap.xml: ---

          <?xml version="1.0" ?>
          <products>
          <product name="pen" />
          <product name="pencil" />
          <product name="cardboard box" />
          <product name="newspaper" />
          </products>

          --- cool.xml: ---

          <?xml version="1.0" ?>
          <products>
          <product name="iPod" />
          <product name="TiVo" />
          </products>

          --- fast.xml: ---

          <?xml version="1.0" ?>
          <products>
          <product name="Mustang" />
          <product name="Miata" />
          <product name="Thunderbird" />
          </products>
          • 2. Re: ComboBox to Load New XML file
            walkthenose Level 1
            You are the man!. I need to play modify it just a little to get it to do a couple of tricks, but it is a great starting point. thank you.