So you have a HTTPService result with 2 or more objects in there and everything works fine. Then, you test the same service with only 1 result being returned and you get:
Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy@ ... to mx.collections.ArrayCollection.
This is the 'single result from HTTPService breaks my app' problem!
The problem is that when only one result is returned, there is only one object, so it isn't cast as an ArrayCollection. When you try to iterate through your result set, your script is trying to access nodes on the object rather than accessing objects in an ArrayCollection.
Using a quick bit of run-time type checking, we can make sure we always get an ArrayCollection. The following function accepts you result object, checks whether it's typed as an ObjectProxy or not, then ensures an ArrayCollection is always returned.
private function checkResultType( d:Object ) :ArrayCollection
{
/* Force ArrayCollection conversion for single result */
if( d is ObjectProxy )
{
return new ArrayCollection( [ d ] );
}
else
{
return d as ArrayCollection;
}
}