Correct ... but that's just because I'm lazy and wanted to play with objectToInstance for automation purposes, as our model and XML responses should always be in structural sync. In a previous iteration, I was just mapping by hand.
I'll have to look more into AsyncToken, Tracy ... Got any recommended reading? Thanks for the starting point. --- In flexcoders@yahoogroups.com, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > I'd assume your companies objects' members exactly match the nodes in the xml ? > > so if your xml has a node called "name" you have a property on your companies object called 'name' ? > > Grant. > > ----- Original Message ----- > From: brent_trx [EMAIL PROTECTED] > To: flexcoders@yahoogroups.com > Sent: 1/31/07 4:44 PM > Subject: [flexcoders] Re: Flex 2 HTTPService best practices > > > Here's a snippet from my XMLUtils class that converts an XML list of > > "companies" to an ArrayCollection of Company objects (relies on Darron > > Schall's ObjectTranslator tools for convenience): > > > > /****************************************************** > > * Convert from XML List to Company ArrayCollection > > ******************************************************/ > > public static function > > companiesXMLDecoder(xml:XMLDocument):ArrayCollection { > > var companyCollection:ArrayCollection = new ArrayCollection(); > > var xmlDecoder:SimpleXMLDecoder = new SimpleXMLDecoder(); > > > > if (xml.firstChild.childNodes.length > 0) { > > var objectTree:Object = xmlDecoder.decodeXML(xml.firstChild); > > var companies:Array; > > > > if (objectTree.company is Array) companies = objectTree.company; > > else companies = new Array(objectTree.company); > > > > for (var i:int=0; i < companies.length; i++) { > > var company:Company = > > ObjectTranslator.objectToInstance(companies[i], Company) as Company; > > companyCollection.addItem(company); > > } > > } > > return companyCollection; > > } > > > > > > ----- and now the HTTPService definition ---- > > > > > > > > > > > > > > ... the event.result received by getCompaniesResultHandler will be an > > ArrayCollection of Company objects. =] > > > > > > > > > > --- In flexcoders@yahoogroups.com, "grant@" wrote: > > > > > > I'd love to see an example, we were about to parse the XML and create > > our own array objects with the correct types for binding but this sounds > > like a much cleaner method. > > > > > > Cheers, > > > Grant > > > > > > ----- Original Message ----- > > > From: brent_trx brent.dearth@ > > > To: flexcoders@yahoogroups.com > > > Sent: 1/31/07 4:27 PM > > > Subject: [flexcoders] Re: Flex 2 HTTPService best practices > > > > > > > I was facing a very similar issue just recently. I had all these AS > > > > model classes that mapped identical properties in accordance to the > > > > backend objects I was dealing with, but no FDS-style convenience > > > > mechanism to handle typing via HTTPService calls. What I found out > > is > > > > the beauty of the "xmlDecode" and "xmlEncode" methods. > > > > > > > > When you use the xmlDecode method, passing it a function reference, > > > > that function will expect an XMLDocument object that is generated > > > > automatically by the service. You can then take that XMLDocument, > > > > iterate through it, building and returning objects of whatever type > > > > you desire. When you access "event.result" in your handler function, > > > > that property value will be typed based on your decoder return type. > > > > So "event.result" is now, say a User object, rather than a user xml > > > > node representation. > > > > > > > > The beauty of this strategy is, at any point, your transport > > mechanism > > > > becomes disposable. If you suddenly decide to switch from XML to > > JSON > > > > as your transport mechanism of choice, you only need to code some > > > > decoder / encoder functions, and you're done. No need to change > > what, > > > > say, a datagrid expects. Very elegant architecture. > > > > > > > > I recommend taking a look at AS3's SimpleXMLDecoder class, along > > with > > > > Darron Schall's ObjectTranslator class, which makes writing an XML > > > > decoder a breeze. > > > > > > > > If anyone is interested, I can post a sample. >