Question

Im using HTTPservice to load XML and show the results in a list - it works when there are more than 1 XML record found.... but when there is only ONE single returned XML record it gets treated differently for some reason and generates this error:

Suspended: TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy

I see posts like this:

http://anupushkaran.blogspot.com/2010/02/typeerror-error-1034-type-coercion.html

but I cant figure out how to adapt it to my HTTPService resultHandler code block...

Im using FB 4.6 and my XML structure looks like the following:

SiteXYZ
   Events
      EventListing

and all the data I want to use is under the EventListing Node.

I've tested some code that can detect when the length of whats returned so I think I can just detect when the length is 1 and then handle something differently -- not sure what though.

Another thing Im seeing that I think gets me close... when I look at the network monitor's TreeView > Response > Response Body I can see that on a succesful trip, the body comes back like:

SiteXYZ
  Events
     EventListing
        [0]
        [1]....  and so on....

But on the cases where its a SINGLE record returned, the body of the response comes back like:

SiteXYZ
   Events
      EventListing

so shouldnt I be able to detect when its just ONE returned record and then set the list dataProvider accordingly? so that when its a lot of returned records the dataprovider is set with:

list1.dataProvider = myXML.lastResult.SiteXYZ.Events.EventListing;

but when its just ONE returned record, how would that dataProvider be set? this didnt work:

list1.dataProvider = lfXML.lastResult.LeisureFun.Events;

can anyone help with this? is my approach way off base? sorry for the rambling nature of the question but as I typed it, I stopped about 5 times and tried a number of things that came to mind as I thought through it... still nothing worked though... I feel like Im onto something (could be wrong though) but just cant solve it yet.

Was it helpful?

Solution

Answer was in the original website I referenced....

i took a closer look at what that post said the problem presented was and how that code snippet addressed it and was able to get it to work for me by putting it in my resultHandler block...

arr=new ArrayCollection();
if(event.result.SiteXYZ.Events.EventListing is ArrayCollection)
{
arr = ArrayCollection(event.result.SiteXYZ.Events.EventListing);
}
if(event.result.SiteXYZ.Events.EventListing is ObjectProxy)
{
arr =new ArrayCollection(ArrayUtil.toArray
    (event.result.SiteXYZ.Events.EventListing));
}

now when there is one record returned it shows fine... same for multiple records returned.

thanks for the help though... I'll definately save this snippet for future use!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top