Ok, I understand!!! (Finally!) thanks!!! brad -----Original Message----- From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Tracy Spratt Sent: Wednesday, February 20, 2008 2:47 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] Re: Best Practices:HTTPService, E4X, XML and dataProvider
For the XMLList collection, do this: public var dpCollection:XMLListCollection; dpList = event.result.month; dpCollection = new XMLListCollection(dpList); One suggestion for flexibility: Keep a reference to the root of the XML. My advised code below: private var _xmlResult:XML; public var _dpCollection:XMLListCollection; //the leading underscore just indicates that this is an instance scoped var public function resultHandler(event:ResultEvent):void { _xmlResult = XML(event.result); //you can also use the "as" operator trace(_xmlResult.toXMLString()); //so you can see exactly what you have var xlMonths:XMLList = _xmlResult.month; //this interim var not required, just for clarity and debugging _dpCollection = new XMLListCollection(xlMonths); linechart.dataProvider = _dpCollection; //this is find, alternatively mark var [Bindable] and bind linechart dataProvider to var }// resultHandler The "strong typing" is really a separate issue. The above is fine unless you have MANY renderers on screen at once. I'd say do it like above first, and go to the ArrayCollection of strongly typed objects if necessary. The creation of the ArrayCollection is a manual process. You will for-loop over each xml node in the XMLList, create a value object, and assign the object property values from the xml atribute values (often the VO takes an xml node and does this itself). Then you addItem() the item object to the ArrayCollection. All this happens in the result handler. Tracy _____ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Brad Bueche Sent: Wednesday, February 20, 2008 1:56 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] Re: Best Practices:HTTPService, E4X, XML and dataProvider Thank you very much for taking the time to give that answer. Its helping a lot I guess for turning this into a XMLListCollection and hooking it up to my dataProvider I'd do the following? //******************************* [Bindable] public var dpCollection:XMLListCollection = new XMLListCollection (); public var dpList:XMLList = new XMLList(); [...snip...] public function resultHandler(event:ResultEvent):void { dpList = event.result.month; dpCollection = dpList; linechart.dataProvider = dpCollection; } /***************************** Is this correct? But then where is the strong typing? I WILL be doing grids and charts with hundreds of data points (for reporting, query only, purposes), so if I am reading you correctly I need to put this into an ArrayCollection (which I think, but I'm not sure, is different than an XMLListcollection?). thanks, brad -----Original Message----- From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Tracy Spratt Sent: Wednesday, February 20, 2008 11:43 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Best Practices:HTTPService, E4X, XML and dataProvider If you are not going to programatically update an individual data provider item, them XMLList will be fine. However, if you ever want to have a user update a property of an item, in some editable cell for example, then you need to wrap the XMLList in an XMLListCollection. This is because when you use the collection API to modify the data, events are dispatched to ensure the UI updates to match the data update. This is similar to the relationship between Array and ArrayCollection. There is no performance reason not to use a collection. If you do not, then Flex wraps your XMLList or Array in a collection itself. So, there are no reasons not to use a collection, except for one more line of code, and several reasons you should. Performance caveat: It has become clear that accessing data an xml node is significantly slower than accessing data in a strongly typed object. This can be noticable if you have, say, a large datagrid that displays hundreds of cells. If this is the case with your app, then best practice is to pre- process the e4x xml into strongly typed objects in an ArrayCollection. Tracy --- In [EMAIL PROTECTED] <mailto:flexcoders%40yahoogroups.com> ups.com, "Brad Bueche" <[EMAIL PROTECTED]> wrote: > > Thanks to this group, I have come a long way in understanding this. I > want to check my setup and see if I still have further to go. Is this > the preferred way to set up a dataprovider when pulling XML in E4X > format via HTTPService? Or do I still need to some how incorporate > XMLListCollection here? > > public var xmlService:HTTPService = new HTTPService(); > public var dataProvider:XMLList = new XMLList(); > > public function loadXML():void > { > xmlService.url = "http://hostname/ <http://hostname/Data/createXML.php> Data/createXML.php"; > > xmlService.resultFormat = "e4x"; > xmlService.addEventListener(ResultEvent.RESULT, > resultHandler); > xmlService.send(); > } > > public function resultHandler(event:ResultEvent):void > { > dataProvider = event.result.month; > } >