2 Replies Latest reply on May 26, 2010 7:51 PM by UbuntuPenguin

    XML-based dataprovider of Combobox / Dropdownlist (spark)


      Hey guys,

      I am struggling a bit with a problem...


      I have an XML file which I use as a dataprovider for a combobox / dropdownlist. If I do that just in Flex with MXML (with a HTTP Service call and using its last result) it is working fine. However I need to replace that XML file dynamically.


      But if I assign a a section of a dynamically loaded XML file (loading is successful (e.g. xmlFile.Sensors) as dataprovider I get that message:


      Type Coercion failed: cannot convert XMLList@18d8b629 to mx.collections.IList.


      Well, I came around by that:


      var collection:XMLListCollection = new XMLListCollection();
      for each (var t:XML in sensorXml.Sensors)


      ...and using the collection as a dataprovider. But seems a bit unuseful...isn't there a faster / more direct approach to populate the dropdownlist with its contents? Especially since e.g. the dataGrid offers to use XML files directly as dataproviders...

        • 1. Re: XML-based dataprovider of Combobox / Dropdownlist (spark)
          UbuntuPenguin Level 4

          Try ,

          var collection:XMLListCollection = new XMLListCollection();
          collection.source = sensorXml.Sensors;


          Here is a link that goes into more depth ,


          1 person found this helpful
          • 2. Re: XML-based dataprovider of Combobox / Dropdownlist (spark)
            David_F57 Level 5



            The following is a basic app that will dynamically load your xml result into your comboboxes dataprovider.


            hope it helps






            <?xml version="1.0" encoding="utf-8"?>

            <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"


               xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="955" minHeight="600" creationComplete="app_creationCompleteHandler(event)"">



            import mx.events.FlexEvent;

            import mx.rpc.events.FaultEvent;

            import mx.rpc.events.ResultEvent;


            protected function myXML_resultHandler(event:ResultEvent):void


            xmlMainMenu.source = event.result.children();



            protected function myXML_faultHandler(event:FaultEvent):void


            //Alert.show("Sorry Couldn't load XML","Error Message");



            protected function app_creationCompleteHandler(event:FlexEvent):void









            <s:HTTPService id="myXML" url="data.xml" resultFormat="e4x"

               result="myXML_resultHandler(event)" fault="myXML_faultHandler(event)"/>


            <s:ComboBox x="57" y="142" width="150" labelField="@label">


            <s:XMLListCollection id="xmlMainMenu" />






            the xml



            <?xml version="1.0" encoding="UTF-8" standalone="no" ?>


            <item label="Group One">

            <img url="images/img02.jpg"/>


            <item label="Group Two">

            <img url="images/img05.jpg"/>

            <img url="images/img06.jpg"/>

            <img url="images/img07.jpg"/>


            <item label="Group Three">

            <img url="images/img08.jpg"/>

            <img url="images/img09.jpg"/>

            <img url="images/img10.jpg"/>

            <img url="images/img04.jpg"/>


            <item label="Group Four">

            <img url="images/img04.jpg"/>


            <item label="Group Five">

            <img url="images/img09.jpg"/>

            <img url="images/img06.jpg"/>