In Flex, when sending a HTTP request to the server it may return no results, so if you then try to access any property of an empty response object, flex will throw an error.
In this case you might try applying a little helper function to the result object, it ensures you always have an object in return.
Below is an example. Hope this helps someone.
////////////////////////////////////////////////////
// Function that handles response from the server
///////////////////////////////////////////////////
public function ServerResponseHandler(evt:ResultEvent):void{
var my_images:ArrayCollection = Response2ArrayCollection(evt.result);
}
////////////////////////////////////////////////////
// Helper function
////////////////////////////////////////////////////
public function Response2ArrayCollection(obj:Object):ArrayCollection {
var arr:ArrayCollection;
if(obj is ObjectProxy) {
arr = new ArrayCollection([obj]);
}else{
arr = obj as ArrayCollection;
}
return arr;
}
Comments