RE: [flexcoders] Re: HTTPService not returning ArrayCollection...
This is an issue when you use the default resultFormat=object. This causes Flex to convert your xml into a tree of dynamic objects. There can be problems with this conversion. The problem you posted is one. Another is that if you have strings that look like numbers, they will get converted to numbers. Also, dynamic objects are slower than strongly typed objects, which might be an issue for a complex data grid. There might be other problems as well. If any of these become a problem, I'd advise using resultFormat=e4x, then processing that xml into an Array Collection of strongly typed VOs. And to clarify, with the default resultFormat conversion, you are getting Array, not ArrayCollection. Note Steve's code. Tracy Spratt, Lariat Services, development services available _ From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of Laurence Sent: Wednesday, March 10, 2010 4:46 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: HTTPService not returning ArrayCollection... I discovered that (event.result.people.person.source != null) when the result is an ArrayCollection. So I used that in an if statement so I could choose simply to set my variable equal to the result, or if I had to variable.addItem() the result. Your way is much neater. I'll give that a try, thanks. L. --- In flexcod...@yahoogro mailto:flexcoders%40yahoogroups.com ups.com, valdhor valdhorli...@... wrote: I use new ArrayCollection(ArrayUtil.toArray(event.result)). It works for 1 or more items in the result. --- In flexcod...@yahoogro mailto:flexcoders%40yahoogroups.com ups.com, Laurence LMacNeill@ wrote: I'm trying to read data from an XML file, and put that data into an ArrayCollection. This works great when I have more than one object in the XML file. But when there's only one object in there, my HTTPService RPC returns it as an Object instead of an ArrayCollection of Objects. So when I assign the event.result to my ArrayCollection I get a Cannot Convert to ArrayCollection error message... Let me give an example: MyXMLFile.xml: people person firstNameJoe/firstName lastNameSmith/lastName /person /people If I have more than one person/person pair in my XML file, then they get returned as an ArrayCollection in event.result.people.person. But with only one person/person pair in my XML file, event.result.people.person is an ObjectProxy -- which can't be converted to an ArrayCollection, apparently. If event.result.people had a length property, I could just loop over it for {length} number of times and addItem() each person to my ArrayCollection -- but I see no length property on the event.result... So how do I get this to work? I won't know in advance how many person/person pairs are in the XML file, so I can't make any assumptions about the length... Could be 1, could be 100... Is there a way to programmatically tell whether or not event.result.people.person is an ArrayCollection or an ObjectProxy? If I could tell what it was, then I could use that information to let the program decide how to deal with it... Thanks for any suggestions... Laurence MacNeill Mableton, Georgia, USA
[flexcoders] Re: HTTPService not returning ArrayCollection...
I use new ArrayCollection(ArrayUtil.toArray(event.result)). It works for 1 or more items in the result. --- In flexcoders@yahoogroups.com, Laurence lmacne...@... wrote: I'm trying to read data from an XML file, and put that data into an ArrayCollection. This works great when I have more than one object in the XML file. But when there's only one object in there, my HTTPService RPC returns it as an Object instead of an ArrayCollection of Objects. So when I assign the event.result to my ArrayCollection I get a Cannot Convert to ArrayCollection error message... Let me give an example: MyXMLFile.xml: people person firstNameJoe/firstName lastNameSmith/lastName /person /people If I have more than one person/person pair in my XML file, then they get returned as an ArrayCollection in event.result.people.person. But with only one person/person pair in my XML file, event.result.people.person is an ObjectProxy -- which can't be converted to an ArrayCollection, apparently. If event.result.people had a length property, I could just loop over it for {length} number of times and addItem() each person to my ArrayCollection -- but I see no length property on the event.result... So how do I get this to work? I won't know in advance how many person/person pairs are in the XML file, so I can't make any assumptions about the length... Could be 1, could be 100... Is there a way to programmatically tell whether or not event.result.people.person is an ArrayCollection or an ObjectProxy? If I could tell what it was, then I could use that information to let the program decide how to deal with it... Thanks for any suggestions... Laurence MacNeill Mableton, Georgia, USA
[flexcoders] Re: HTTPService not returning ArrayCollection...
I discovered that (event.result.people.person.source != null) when the result is an ArrayCollection. So I used that in an if statement so I could choose simply to set my variable equal to the result, or if I had to variable.addItem() the result. Your way is much neater. I'll give that a try, thanks. L. --- In flexcoders@yahoogroups.com, valdhor valdhorli...@... wrote: I use new ArrayCollection(ArrayUtil.toArray(event.result)). It works for 1 or more items in the result. --- In flexcoders@yahoogroups.com, Laurence LMacNeill@ wrote: I'm trying to read data from an XML file, and put that data into an ArrayCollection. This works great when I have more than one object in the XML file. But when there's only one object in there, my HTTPService RPC returns it as an Object instead of an ArrayCollection of Objects. So when I assign the event.result to my ArrayCollection I get a Cannot Convert to ArrayCollection error message... Let me give an example: MyXMLFile.xml: people person firstNameJoe/firstName lastNameSmith/lastName /person /people If I have more than one person/person pair in my XML file, then they get returned as an ArrayCollection in event.result.people.person. But with only one person/person pair in my XML file, event.result.people.person is an ObjectProxy -- which can't be converted to an ArrayCollection, apparently. If event.result.people had a length property, I could just loop over it for {length} number of times and addItem() each person to my ArrayCollection -- but I see no length property on the event.result... So how do I get this to work? I won't know in advance how many person/person pairs are in the XML file, so I can't make any assumptions about the length... Could be 1, could be 100... Is there a way to programmatically tell whether or not event.result.people.person is an ArrayCollection or an ObjectProxy? If I could tell what it was, then I could use that information to let the program decide how to deal with it... Thanks for any suggestions... Laurence MacNeill Mableton, Georgia, USA