views:

238

answers:

1

hello, 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;
    }
+1  A: 

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;
}
www.Flextras.com
i have this as my PHP......header('Content-type: text/plain');echo('<?xml version="1.0" encoding="utf-8"?><list>');echo('<name>"name1"</name>');echo('</list>');......and it does not work with XMLListCollection.. i get this error.....TypeError: Error #1034: Type Coercion failed: cannot convert mx.collections::ArrayCollection@aaa0301 to XMLList... is there something wrong with my PHP?
Rees
That error doesn't make much sense to me. Are you sure your PHP is sending back properly formed XML? Have tried running the PHP results through a validator?
www.Flextras.com
I modified my answer to include a modified code sample.
www.Flextras.com
i think i'm getting closer flextras.. however, for the line myList.source = results; i get the following error prior to compiling...-1067: Implicit coercion of a value of type XML to an unrelated type XMLList. ... i have everything else exactly as you have posted. what else can i be missing?
Rees
I'm writing psuedo code in a browser, so you'll have to excuse the fact that it isn't perfect. XML and XMLList are different types. You can do a cast, like this: myList.source = results as XMLListCollection and that might address it.
www.Flextras.com
ok so i have made it as follows......[Bindable]private var myList:XMLListCollection = new XMLListCollection();...var results:XML = e.result.list.name as XML; ...and.....myList.source = results as XMLListCollection; however, this is still giving me an error....-1067: Implicit coercion of a value of type mx.collections:XMLListCollection to an unrelated type XMLList...i'm still not sure why. if i change... var results:XML...to instead...var results:XMLListCollection = e.result.list.name as XMLListCollection; i still get an error.. any thoughts?
Rees