0

I am trying to load xml data into a List with Flex/MXML. I have a method for getting the XML and putting it into the list (I know that it is reading the data properly) but when I run the application I get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert "User1" to mx.collections.IList.
at Function/<anonymous>()[/Users/Jacob/Documents/Adobe Flash Builder 4.6/App/src/views/MainMenu.mxml:52]

(I deleted some of the error log)

I see that it says that the error is occurring at line 52, which is the following:

<s:List id="xml_list" x="44" y="89" width="232" height="341" dataProvider="{get_xml.lastResult.Array.Item}"></s:List>

I have done some tests and I have realized that the error only occurs when the data to be added is 1 item. If there is more that 1 item then it works perfectly and puts the data in the list.

When the XML has one Item, it looks like this:

<Array>
<Item>Hello</Item>
</Array>

And When the XML has two items, it looks like this:

<Array>
<Item>Hi</Item>
<Item>Hola</Item>
</Array>

So my question is: Is there a way to solve this? Any help is highly appreciated.

Thanks, Jacob

RMK-Jacob
  • 209
  • 1
  • 4
  • 15
  • Could you post roughly what the XML look like when there is one item vs. multiple? I couldn't reproduce the issue with my XML test, so I think there might be something with the XML you have. – Tianzhen Lin Jan 23 '13 at 04:25
  • @TianzhenLin Ok. I edited the above message to show my XML. – RMK-Jacob Jan 23 '13 at 04:38

2 Answers2

0

Try this:

<s:List id="xml_list" x="44" y="89" width="232" height="341" >
    <s:dataProvider>
        <s:XMLListCollection source="{get_xml.lastResult.Array.Item}" />
    </s:dataProvider>
</s:List>
Serge Him
  • 936
  • 6
  • 8
0

I've solved it! I used the basis of the post from Serge Him, but changed his example a little. The code that I have gotten to work is:

<s:List id="games_list" x="44" y="89" width="232" height="341">
    <s:dataProvider>
        <s:ArrayCollection source="{get_games.lastResult.Games.Name}"/>
    </s:dataProvider>
</s:List>

Big thanks to Serge Him who got me pointed in the right direction!

RMK-Jacob
  • 209
  • 1
  • 4
  • 15