Search code examples
xmlactionscript-3apache-flexflex4.5flex-spark

How do I use a local XML file as a DataProvider for a Spark List control in Flex 4.5?


I am building a Android app in Flash Builder 4.5 using Flex 4.5.1 and I am having the hardest time using a locally stored (/data/data/app-name/db/pellets) XML file as the DataProvider for a Spark List control. I've looked on the net for the past 3 days and have tried a bunch of different ways to get the code working but to no avail.

I have a SkinnablePopUpContainer with a Spark List control (list1) that I'd like to populate with the "name" element in my locally stored XML file (pelletdb.xml) that contains about 170 entries with 6 elements each. The XML looks like this:

<tin>
  <pellet>
    <caliber>0.177</caliber>
    <name>AA Field</name>
    <bc>0.0210</bc>
    <weight>8.400</weight>
    <style>N/A</style>
    <material>Lead</material>
  </pellet>
  <pellet>
    <caliber>0.177</caliber>
    <name>Beeman Bearcub</name>
    <bc>0.0110</bc>
    <weight>8.000</weight>
    <style>N/A</style>
    <material>Lead</material>
  </pellet>
</tin>

When I click on the list1 entry I'd like to populate some Labels. I haven't been able to get the XML data into an ArrayCollection to be used as the DataProvider for my Spark List control. I know I must be doing something wrong someplace, any help would be greatly appreciated!


Solution

  • As dataprovider for the List control you need an ilist datatype. So you could do something like

    list.dataProvider = new XMLListCollection(xml.children());
    

    You can see a sample on Peter Dehaans great Flex example page: Using an XML data provider with the Spark List control in Flex 4