ArrayCollection error in Flex not accepting individual XML nodes - alternatives?

I am getting this error when I receive XML that only has 1 node (no duplicate nodes) and I am trying to save to an ArrayCollection. -When I have MORE than 1 hostname "name" ... I DO NOT get an error.

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

      

this error occurs as a line of code:

myList= e.result.list.name;

      

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

the 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;
        }

      

+2


a source to share


2 answers


The parameter resultFormat

must 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();

      

Then you can get the results like this:



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

      

(All credits to Amarkhosh, I banged my head about this for one hour but almost missed his comment!)

+1


a source


You cannot directly assign XML

or even to XMLList

a type variable ArrayCollection

. Use XMLListCollection

and pass data to your constructor.



[Bindable]
private var myList:XMLListCollection;

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

      

0


a source







All Articles