Search code examples
apache-flexflash-builderdataprovider

what dataprovider in flex (aside from ArrayCollection) will work for single, non-repeating XML nodes?


i asked this question before but haven't been able to get an answer.. i get the following error when i retrieve an XML that only has 1 node (no repeating nodes) from a PHP page 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;

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

Solution

  • XMLListCollection

    http://livedocs.adobe.com/flex/3/langref/mx/collections/XMLListCollection.html

    Try something like this (This is in Psuedo code):

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

    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{
        var results : XML = e.result as XML;
        myList.source = results;
    }