2

i get this error when i retrieve an XML that only has 1 node (no repeating nodes) and i try to store in an ArrayCollection. -When I have MORE than 1 "name" nodes...i do NOT get an error.

TypeError: Error #1034: Type Coercion failed: cannot convert "XXXXXX" to mx.collections.ArrayCollection.

this error occurs as the line of code:

myList= e.result.list.name;

Why can't ArrayCollection work with a single node? I'm using this ArrayCollection as a dataprovider for a Component -is there an alternative I can use that will take BOTH single and repeating nodes as well as work as a dataprovider? Thanks in advance!

code:

[Bindable]
private var myList:ArrayCollection= new ArrayCollection();

        private function getList(e:Event):void{

            var getStudyLoungesService:HTTPService = new HTTPService();
            getStuffService.url = "website.com/asdf.php";
            getStuffService.addEventListener(ResultEvent.RESULT, onGetList);
            getStuffService.send();

        }

        private function onGetList(e:ResultEvent):void{

            myList= e.result.list.name;
        }
Rees
  • 1,757
  • 9
  • 33
  • 50

2 Answers2

1

The resultFormat should be set to e4x:

var getStudyLoungesService:HTTPService = new HTTPService();
getStuffService.url = "website.com/asdf.php";
getStuffService.resultFormat = "e4x";
getStuffService.addEventListener(ResultEvent.RESULT, onGetList);
getStuffService.send();

You can then retrieve the results as follows:

new XMLListCollection(e.result.list.name);

(All credits to Amarghosh, been banging my head on that one for hours, but nearly missed his comment!)

Sébastien Le Callonnec
  • 26,254
  • 8
  • 67
  • 80
0

You cannot directly assign an XML or even an XMLList to a variable of type ArrayCollection. Use an XMLListCollection and pass the data to its constructor.

[Bindable]
private var myList:XMLListCollection;

myList = new XMLListCollection(e.result.list.name);
Amarghosh
  • 58,710
  • 11
  • 92
  • 121
  • thanks Amarghosh. However, it doesn't look like XMLList is a valid dataprovider.. I'm getting this error: TypeError: Error #1034: Type Coercion failed: cannot convert mx.collections::ArrayCollection@ddbc7c1 to XMLList. Is there another data type that I can still use? – Rees Apr 30 '10 at 23:55
  • it's not XMLList, it's `XMLListCollection`. Change the type of myList from array collection to xmllist collection – Amarghosh May 03 '10 at 04:32
  • hi again amarghosh, i have tried XMLListCollection, however recieved this error: TypeError: Error #1034: Type Coercion failed: cannot convert mx.collections::ArrayCollection@aaa0301 to XMLList. i am sure when it is of type XMLList because private var studyLounges:XMLListCollection; is my initialization. any other thoughts what alternative data types? – Rees May 16 '10 at 07:59
  • Are you sure you're receiving XML in your result? – Mike Sickler Aug 01 '10 at 14:48
  • 1
    @Rees In your HTTPService, set the attribute `resultFormat="e4x"`. Thanks @Mike for triggering it :) – Amarghosh Aug 01 '10 at 15:16