Re: [flexcoders] Inspecting data from HTTPService result to an ArrayCollection
I am now using e4x as you suggest. I wrote a custom dataTipFunction to display the correct information. I have tried many things, but I have not been able to get the X - axis labels working. How can I write a custom axis label rendering for the below code ? ?xml version=1.0? !-- charts/HTTPServiceToXMLListCollection.mxml -- mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; creationComplete=srv.send() mx:Script![CDATA[ import mx.utils.ArrayUtil; ]]/mx:Script mx:HTTPService id=srv url=data.xml resultFormat=e4x / mx:XMLListCollection id=myAC source={srv.lastResult.result} / mx:Panel title=Line Chart mx:LineChart id=chart dataProvider={myAC} showDataTips=true mx:horizontalAxis mx:CategoryAxis categoryField=month/ /mx:horizontalAxis mx:series mx:LineSeries yField=apple name=Apple/ mx:LineSeries yField=orange name=Orange/ mx:LineSeries yField=banana name=Banana/ /mx:series /mx:LineChart /mx:Panel /mx:Application On Thu, Jul 3, 2008 at 7:41 AM, Stephen More step.om wrote: On Wed, Jul 2, 2008 at 6:29 PM, Tracy Spratt tsp...com wrote: I advise using resultFormat=e4x, a result handler function, and an instance variable to hold the xmlResult. I started out using e4x until I ran into what I think is a bug: https://bugs.adobe.com/jira/browse/SDK-15976 DataTips in mx:LineChart does not like the e4x format. I guess I should go back to using e4x and write a custom dataTipFunction that actually works. -Steve The best performance, especially in a multi-renderer DataGrid, will be if you manually convert the XML node data ino an ArrayCollection of strongly typed value objects. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Sean Clark Hess Sent: Wednesday, July 02, 2008 4:05 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Inspecting data from HTTPService result to an ArrayCollection Ah, got it. The mx:Model tag converts everything to a flat object. So the minute you use it, you no longer have xml. It's still easy enough to loop through though. var result:Object = myData.getItemAt(0); for (var name:String in result) { trace(name + :: + result[name]); } should output apple :: 81768 orange :: 60310 banana :: 43357 On Wed, Jul 2, 2008 at 1:46 PM, Stephen More [EMAIL PROTECTED] wrote: Here is my output: DEBUG: 2 null [object Object] CHECK : false CHECK : false Here is all the code: ?xml version=1.0? !-- charts/XMLFileToArrayCollectionDataProvider.mxml -- mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; width=100% height=100% mx:Script import mx.utils.ArrayUtil; /mx:Script mx:Model id=results source=../assets/data.xml/ mx:ArrayCollection id=myData source={ArrayUtil.toArray(results.result)} / mx:Panel title=Line Chart mx:LineChart id=chart dataProvider={myData} showDataTips=true mx:horizontalAxis mx:CategoryAxis categoryField=month/ /mx:horizontalAxis mx:series mx:LineSeries yField=banana displayName=Banana/ mx:LineSeries yField=apple displayName=Apple/ mx:LineSeries yField=orange displayName=Orange/ /mx:series /mx:LineChart mx:Button id=iconButton label=Button with Icon labelPlacement=right color=#993300 click=printMessage(event);/ mx:Script ![CDATA[ import flash.events.Event; // Event handler function to print a message // describing the selected Button control. private function printMessage(event:Event):void { //message.text += event.target.label + pressed + \n; var myXML:XML; myXML = myData.getItemAt(0) as XML; trace( DEBUG: + myData.length + + myXML ); trace( myData.getItemAt(0) ); trace(CHECK : + (myData.getItemAt(0) is XML)); trace(CHECK : + (myData.getItemAt(0) is XMLList)); } ]] /mx:Script /mx:Panel /mx:Application On Wed, Jul 2, 2008 at 3:34 PM, Sean Clark Hess [EMAIL PROTECTED] wrote: What do you get when you trace myData.getItemAt(0)? That will return null if it isn't an XML. You can do this too: trace(CHECK : + (myData.getItemAt(0) is XML)); You can check to see if it is an XMLList too, but I thought looking at it, it seemed like a flat xml. On Wed, Jul 2, 2008 at 1:32 PM, Stephen More [EMAIL PROTECTED] wrote: Thats what I was thinking but when I try: var myXML:XML; myXML = myData.getItemAt(0) as XML; trace( DEBUG: + myXML ); I get DEBUG: null On Wed, Jul 2, 2008 at 2:30 PM, Sean Clark Hess [EMAIL PROTECTED] wrote: Each row is an xml object... So, (myData.getItemAt(i) as XML).children() Then you could loop through the children and ask them for their name. After the as XML step you can do anything you can normally do with the XML object On Wed, Jul 2, 2008 at 12:11 PM, Stephen More [EMAIL PROTECTED] wrote: ( Example code taken from: http://livedocs.adobe.com/flex/201/html/charts_intro_108_12.html ) Here is the dataset I am trying
Re: [flexcoders] Inspecting data from HTTPService result to an ArrayCollection
On Wed, Jul 2, 2008 at 6:29 PM, Tracy Spratt tsp...com wrote: I advise using resultFormat=e4x, a result handler function, and an instance variable to hold the xmlResult. I started out using e4x until I ran into what I think is a bug: https://bugs.adobe.com/jira/browse/SDK-15976 DataTips in mx:LineChart does not like the e4x format. I guess I should go back to using e4x and write a custom dataTipFunction that actually works. -Steve The best performance, especially in a multi-renderer DataGrid, will be if you manually convert the XML node data ino an ArrayCollection of strongly typed value objects. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Sean Clark Hess Sent: Wednesday, July 02, 2008 4:05 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Inspecting data from HTTPService result to an ArrayCollection Ah, got it. The mx:Model tag converts everything to a flat object. So the minute you use it, you no longer have xml. It's still easy enough to loop through though. var result:Object = myData.getItemAt(0); for (var name:String in result) { trace(name + :: + result[name]); } should output apple :: 81768 orange :: 60310 banana :: 43357 On Wed, Jul 2, 2008 at 1:46 PM, Stephen More [EMAIL PROTECTED] wrote: Here is my output: DEBUG: 2 null [object Object] CHECK : false CHECK : false Here is all the code: ?xml version=1.0? !-- charts/XMLFileToArrayCollectionDataProvider.mxml -- mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; width=100% height=100% mx:Script import mx.utils.ArrayUtil; /mx:Script mx:Model id=results source=../assets/data.xml/ mx:ArrayCollection id=myData source={ArrayUtil.toArray(results.result)} / mx:Panel title=Line Chart mx:LineChart id=chart dataProvider={myData} showDataTips=true mx:horizontalAxis mx:CategoryAxis categoryField=month/ /mx:horizontalAxis mx:series mx:LineSeries yField=banana displayName=Banana/ mx:LineSeries yField=apple displayName=Apple/ mx:LineSeries yField=orange displayName=Orange/ /mx:series /mx:LineChart mx:Button id=iconButton label=Button with Icon labelPlacement=right color=#993300 click=printMessage(event);/ mx:Script ![CDATA[ import flash.events.Event; // Event handler function to print a message // describing the selected Button control. private function printMessage(event:Event):void { //message.text += event.target.label + pressed + \n; var myXML:XML; myXML = myData.getItemAt(0) as XML; trace( DEBUG: + myData.length + + myXML ); trace( myData.getItemAt(0) ); trace(CHECK : + (myData.getItemAt(0) is XML)); trace(CHECK : + (myData.getItemAt(0) is XMLList)); } ]] /mx:Script /mx:Panel /mx:Application On Wed, Jul 2, 2008 at 3:34 PM, Sean Clark Hess [EMAIL PROTECTED] wrote: What do you get when you trace myData.getItemAt(0)? That will return null if it isn't an XML. You can do this too: trace(CHECK : + (myData.getItemAt(0) is XML)); You can check to see if it is an XMLList too, but I thought looking at it, it seemed like a flat xml. On Wed, Jul 2, 2008 at 1:32 PM, Stephen More [EMAIL PROTECTED] wrote: Thats what I was thinking but when I try: var myXML:XML; myXML = myData.getItemAt(0) as XML; trace( DEBUG: + myXML ); I get DEBUG: null On Wed, Jul 2, 2008 at 2:30 PM, Sean Clark Hess [EMAIL PROTECTED] wrote: Each row is an xml object... So, (myData.getItemAt(i) as XML).children() Then you could loop through the children and ask them for their name. After the as XML step you can do anything you can normally do with the XML object On Wed, Jul 2, 2008 at 12:11 PM, Stephen More [EMAIL PROTECTED] wrote: ( Example code taken from: http://livedocs.adobe.com/flex/201/html/charts_intro_108_12.html ) Here is the dataset I am trying to work with: data result month=Jan-04 apple81768/apple orange60310/orange banana43357/banana /result result month=Feb-04 apple81156/apple orange58883/orange banana49280/banana /result /data The flex code will look like this: mx:HTTPService id=srv url=../assets/data.xml useProxy=false result=myData=ArrayCollection(srv.lastResult.data.result) / How can I interrogate the ArrayCollection named myData so that it will return apple, orange, and banana ? I am not looking to get the numerical values, I want to get the xml name. -Thanks Steve More
[flexcoders] Inspecting data from HTTPService result to an ArrayCollection
( Example code taken from: http://livedocs.adobe.com/flex/201/html/charts_intro_108_12.html ) Here is the dataset I am trying to work with: data result month=Jan-04 apple81768/apple orange60310/orange banana43357/banana /result result month=Feb-04 apple81156/apple orange58883/orange banana49280/banana /result /data The flex code will look like this: mx:HTTPService id=srv url=../assets/data.xml useProxy=false result=myData=ArrayCollection(srv.lastResult.data.result) / How can I interrogate the ArrayCollection named myData so that it will return apple, orange, and banana ? I am not looking to get the numerical values, I want to get the xml name. -Thanks Steve More
Re: [flexcoders] Inspecting data from HTTPService result to an ArrayCollection
Each row is an xml object... So, (myData.getItemAt(i) as XML).children() Then you could loop through the children and ask them for their name. After the as XML step you can do anything you can normally do with the XML object On Wed, Jul 2, 2008 at 12:11 PM, Stephen More [EMAIL PROTECTED] wrote: ( Example code taken from: http://livedocs.adobe.com/flex/201/html/charts_intro_108_12.html ) Here is the dataset I am trying to work with: data result month=Jan-04 apple81768/apple orange60310/orange banana43357/banana /result result month=Feb-04 apple81156/apple orange58883/orange banana49280/banana /result /data The flex code will look like this: mx:HTTPService id=srv url=../assets/data.xml useProxy=false result=myData=ArrayCollection(srv.lastResult.data.result) / How can I interrogate the ArrayCollection named myData so that it will return apple, orange, and banana ? I am not looking to get the numerical values, I want to get the xml name. -Thanks Steve More
Re: [flexcoders] Inspecting data from HTTPService result to an ArrayCollection
Thats what I was thinking but when I try: var myXML:XML; myXML = myData.getItemAt(0) as XML; trace( DEBUG: + myXML ); I get DEBUG: null On Wed, Jul 2, 2008 at 2:30 PM, Sean Clark Hess [EMAIL PROTECTED] wrote: Each row is an xml object... So, (myData.getItemAt(i) as XML).children() Then you could loop through the children and ask them for their name. After the as XML step you can do anything you can normally do with the XML object On Wed, Jul 2, 2008 at 12:11 PM, Stephen More [EMAIL PROTECTED] wrote: ( Example code taken from: http://livedocs.adobe.com/flex/201/html/charts_intro_108_12.html ) Here is the dataset I am trying to work with: data result month=Jan-04 apple81768/apple orange60310/orange banana43357/banana /result result month=Feb-04 apple81156/apple orange58883/orange banana49280/banana /result /data The flex code will look like this: mx:HTTPService id=srv url=../assets/data.xml useProxy=false result=myData=ArrayCollection(srv.lastResult.data.result) / How can I interrogate the ArrayCollection named myData so that it will return apple, orange, and banana ? I am not looking to get the numerical values, I want to get the xml name. -Thanks Steve More
Re: [flexcoders] Inspecting data from HTTPService result to an ArrayCollection
What do you get when you trace myData.getItemAt(0)? That will return null if it isn't an XML. You can do this too: trace(CHECK : + (myData.getItemAt(0) is XML)); You can check to see if it is an XMLList too, but I thought looking at it, it seemed like a flat xml. On Wed, Jul 2, 2008 at 1:32 PM, Stephen More [EMAIL PROTECTED] wrote: Thats what I was thinking but when I try: var myXML:XML; myXML = myData.getItemAt(0) as XML; trace( DEBUG: + myXML ); I get DEBUG: null On Wed, Jul 2, 2008 at 2:30 PM, Sean Clark Hess [EMAIL PROTECTED]seanhess%40gmail.com wrote: Each row is an xml object... So, (myData.getItemAt(i) as XML).children() Then you could loop through the children and ask them for their name. After the as XML step you can do anything you can normally do with the XML object On Wed, Jul 2, 2008 at 12:11 PM, Stephen More [EMAIL PROTECTED]stephen.more%40gmail.com wrote: ( Example code taken from: http://livedocs.adobe.com/flex/201/html/charts_intro_108_12.html ) Here is the dataset I am trying to work with: data result month=Jan-04 apple81768/apple orange60310/orange banana43357/banana /result result month=Feb-04 apple81156/apple orange58883/orange banana49280/banana /result /data The flex code will look like this: mx:HTTPService id=srv url=../assets/data.xml useProxy=false result=myData=ArrayCollection(srv.lastResult.data.result) / How can I interrogate the ArrayCollection named myData so that it will return apple, orange, and banana ? I am not looking to get the numerical values, I want to get the xml name. -Thanks Steve More
Re: [flexcoders] Inspecting data from HTTPService result to an ArrayCollection
Here is my output: DEBUG: 2 null [object Object] CHECK : false CHECK : false Here is all the code: ?xml version=1.0? !-- charts/XMLFileToArrayCollectionDataProvider.mxml -- mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; width=100% height=100% mx:Script import mx.utils.ArrayUtil; /mx:Script mx:Model id=results source=../assets/data.xml/ mx:ArrayCollection id=myData source={ArrayUtil.toArray(results.result)} / mx:Panel title=Line Chart mx:LineChart id=chart dataProvider={myData} showDataTips=true mx:horizontalAxis mx:CategoryAxis categoryField=month/ /mx:horizontalAxis mx:series mx:LineSeries yField=banana displayName=Banana/ mx:LineSeries yField=apple displayName=Apple/ mx:LineSeries yField=orange displayName=Orange/ /mx:series /mx:LineChart mx:Button id=iconButton label=Button with Icon labelPlacement=right color=#993300 click=printMessage(event);/ mx:Script ![CDATA[ import flash.events.Event; // Event handler function to print a message // describing the selected Button control. private function printMessage(event:Event):void { //message.text += event.target.label + pressed + \n; var myXML:XML; myXML = myData.getItemAt(0) as XML; trace( DEBUG: + myData.length + + myXML ); trace( myData.getItemAt(0) ); trace(CHECK : + (myData.getItemAt(0) is XML)); trace(CHECK : + (myData.getItemAt(0) is XMLList)); } ]] /mx:Script /mx:Panel /mx:Application On Wed, Jul 2, 2008 at 3:34 PM, Sean Clark Hess [EMAIL PROTECTED] wrote: What do you get when you trace myData.getItemAt(0)? That will return null if it isn't an XML. You can do this too: trace(CHECK : + (myData.getItemAt(0) is XML)); You can check to see if it is an XMLList too, but I thought looking at it, it seemed like a flat xml. On Wed, Jul 2, 2008 at 1:32 PM, Stephen More [EMAIL PROTECTED] wrote: Thats what I was thinking but when I try: var myXML:XML; myXML = myData.getItemAt(0) as XML; trace( DEBUG: + myXML ); I get DEBUG: null On Wed, Jul 2, 2008 at 2:30 PM, Sean Clark Hess [EMAIL PROTECTED] wrote: Each row is an xml object... So, (myData.getItemAt(i) as XML).children() Then you could loop through the children and ask them for their name. After the as XML step you can do anything you can normally do with the XML object On Wed, Jul 2, 2008 at 12:11 PM, Stephen More [EMAIL PROTECTED] wrote: ( Example code taken from: http://livedocs.adobe.com/flex/201/html/charts_intro_108_12.html ) Here is the dataset I am trying to work with: data result month=Jan-04 apple81768/apple orange60310/orange banana43357/banana /result result month=Feb-04 apple81156/apple orange58883/orange banana49280/banana /result /data The flex code will look like this: mx:HTTPService id=srv url=../assets/data.xml useProxy=false result=myData=ArrayCollection(srv.lastResult.data.result) / How can I interrogate the ArrayCollection named myData so that it will return apple, orange, and banana ? I am not looking to get the numerical values, I want to get the xml name. -Thanks Steve More
Re: [flexcoders] Inspecting data from HTTPService result to an ArrayCollection
Ah, got it. The mx:Model tag converts everything to a flat object. So the minute you use it, you no longer have xml. It's still easy enough to loop through though. var result:Object = myData.getItemAt(0); for (var name:String in result) { trace(name + :: + result[name]); } should output apple :: 81768 orange :: 60310 banana :: 43357 On Wed, Jul 2, 2008 at 1:46 PM, Stephen More [EMAIL PROTECTED] wrote: Here is my output: DEBUG: 2 null [object Object] CHECK : false CHECK : false Here is all the code: ?xml version=1.0? !-- charts/XMLFileToArrayCollectionDataProvider.mxml -- mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; width=100% height=100% mx:Script import mx.utils.ArrayUtil; /mx:Script mx:Model id=results source=../assets/data.xml/ mx:ArrayCollection id=myData source={ArrayUtil.toArray(results.result)} / mx:Panel title=Line Chart mx:LineChart id=chart dataProvider={myData} showDataTips=true mx:horizontalAxis mx:CategoryAxis categoryField=month/ /mx:horizontalAxis mx:series mx:LineSeries yField=banana displayName=Banana/ mx:LineSeries yField=apple displayName=Apple/ mx:LineSeries yField=orange displayName=Orange/ /mx:series /mx:LineChart mx:Button id=iconButton label=Button with Icon labelPlacement=right color=#993300 click=printMessage(event);/ mx:Script ![CDATA[ import flash.events.Event; // Event handler function to print a message // describing the selected Button control. private function printMessage(event:Event):void { //message.text += event.target.label + pressed + \n; var myXML:XML; myXML = myData.getItemAt(0) as XML; trace( DEBUG: + myData.length + + myXML ); trace( myData.getItemAt(0) ); trace(CHECK : + (myData.getItemAt(0) is XML)); trace(CHECK : + (myData.getItemAt(0) is XMLList)); } ]] /mx:Script /mx:Panel /mx:Application On Wed, Jul 2, 2008 at 3:34 PM, Sean Clark Hess [EMAIL PROTECTED]seanhess%40gmail.com wrote: What do you get when you trace myData.getItemAt(0)? That will return null if it isn't an XML. You can do this too: trace(CHECK : + (myData.getItemAt(0) is XML)); You can check to see if it is an XMLList too, but I thought looking at it, it seemed like a flat xml. On Wed, Jul 2, 2008 at 1:32 PM, Stephen More [EMAIL PROTECTED]stephen.more%40gmail.com wrote: Thats what I was thinking but when I try: var myXML:XML; myXML = myData.getItemAt(0) as XML; trace( DEBUG: + myXML ); I get DEBUG: null On Wed, Jul 2, 2008 at 2:30 PM, Sean Clark Hess [EMAIL PROTECTED]seanhess%40gmail.com wrote: Each row is an xml object... So, (myData.getItemAt(i) as XML).children() Then you could loop through the children and ask them for their name. After the as XML step you can do anything you can normally do with the XML object On Wed, Jul 2, 2008 at 12:11 PM, Stephen More [EMAIL PROTECTED]stephen.more%40gmail.com wrote: ( Example code taken from: http://livedocs.adobe.com/flex/201/html/charts_intro_108_12.html ) Here is the dataset I am trying to work with: data result month=Jan-04 apple81768/apple orange60310/orange banana43357/banana /result result month=Feb-04 apple81156/apple orange58883/orange banana49280/banana /result /data The flex code will look like this: mx:HTTPService id=srv url=../assets/data.xml useProxy=false result=myData=ArrayCollection(srv.lastResult.data.result) / How can I interrogate the ArrayCollection named myData so that it will return apple, orange, and banana ? I am not looking to get the numerical values, I want to get the xml name. -Thanks Steve More
RE: [flexcoders] Inspecting data from HTTPService result to an ArrayCollection
It is a rare case that you want to use mx:Model or the default resultFormat=object. You take the performance hit for the conversion, you have no control over the conversion process (your strings that look like numbers will get converted to numbers, willy nilly) and you wind up with dynamic objects, which have an access peformance penalty. I advise using resultFormat=e4x, a result handler function, and an instance variable to hold the xmlResult. The best performance, especially in a multi-renderer DataGrid, will be if you manually convert the XML node data ino an ArrayCollection of strongly typed value objects. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Sean Clark Hess Sent: Wednesday, July 02, 2008 4:05 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Inspecting data from HTTPService result to an ArrayCollection Ah, got it. The mx:Model tag converts everything to a flat object. So the minute you use it, you no longer have xml. It's still easy enough to loop through though. var result:Object = myData.getItemAt(0); for (var name:String in result) { trace(name + :: + result[name]); } should output apple :: 81768 orange :: 60310 banana :: 43357 On Wed, Jul 2, 2008 at 1:46 PM, Stephen More [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Here is my output: DEBUG: 2 null [object Object] CHECK : false CHECK : false Here is all the code: ?xml version=1.0? !-- charts/XMLFileToArrayCollectionDataProvider.mxml -- mx:Application xmlns:mx=http://www.adobe.com/2006/mxml http://www.adobe.com/2006/mxml width=100% height=100% mx:Script import mx.utils.ArrayUtil; /mx:Script mx:Model id=results source=../assets/data.xml/ mx:ArrayCollection id=myData source={ArrayUtil.toArray(results.result)} / mx:Panel title=Line Chart mx:LineChart id=chart dataProvider={myData} showDataTips=true mx:horizontalAxis mx:CategoryAxis categoryField=month/ /mx:horizontalAxis mx:series mx:LineSeries yField=banana displayName=Banana/ mx:LineSeries yField=apple displayName=Apple/ mx:LineSeries yField=orange displayName=Orange/ /mx:series /mx:LineChart mx:Button id=iconButton label=Button with Icon labelPlacement=right color=#993300 click=printMessage(event);/ mx:Script ![CDATA[ import flash.events.Event; // Event handler function to print a message // describing the selected Button control. private function printMessage(event:Event):void { //message.text += event.target.label + pressed + \n; var myXML:XML; myXML = myData.getItemAt(0) as XML; trace( DEBUG: + myData.length + + myXML ); trace( myData.getItemAt(0) ); trace(CHECK : + (myData.getItemAt(0) is XML)); trace(CHECK : + (myData.getItemAt(0) is XMLList)); } ]] /mx:Script /mx:Panel /mx:Application On Wed, Jul 2, 2008 at 3:34 PM, Sean Clark Hess [EMAIL PROTECTED] mailto:seanhess%40gmail.com wrote: What do you get when you trace myData.getItemAt(0)? That will return null if it isn't an XML. You can do this too: trace(CHECK : + (myData.getItemAt(0) is XML)); You can check to see if it is an XMLList too, but I thought looking at it, it seemed like a flat xml. On Wed, Jul 2, 2008 at 1:32 PM, Stephen More [EMAIL PROTECTED] mailto:stephen.more%40gmail.com wrote: Thats what I was thinking but when I try: var myXML:XML; myXML = myData.getItemAt(0) as XML; trace( DEBUG: + myXML ); I get DEBUG: null On Wed, Jul 2, 2008 at 2:30 PM, Sean Clark Hess [EMAIL PROTECTED] mailto:seanhess%40gmail.com wrote: Each row is an xml object... So, (myData.getItemAt(i) as XML).children() Then you could loop through the children and ask them for their name. After the as XML step you can do anything you can normally do with the XML object On Wed, Jul 2, 2008 at 12:11 PM, Stephen More [EMAIL PROTECTED] mailto:stephen.more%40gmail.com wrote: ( Example code taken from: http://livedocs.adobe.com/flex/201/html/charts_intro_108_12.html http://livedocs.adobe.com/flex/201/html/charts_intro_108_12.html ) Here is the dataset I am trying to work with: data result month=Jan-04 apple81768/apple orange60310/orange banana43357/banana /result result month=Feb-04 apple81156/apple orange58883/orange banana49280/banana /result /data The flex code will look like this: mx:HTTPService id=srv url=../assets/data.xml useProxy=false result=myData=ArrayCollection(srv.lastResult.data.result) / How can I interrogate the ArrayCollection named myData so that it will return apple, orange, and banana ? I am not looking to get the numerical values, I want to get the xml name. -Thanks Steve More
Re: [flexcoders] Inspecting data from HTTPService result to an ArrayCollection
Tracy, can a datagrid read an xml object directly? (Like, an XMLList or XMLListCollection?) If so, why would manually converting it perform better than the original XML? Does it have something to do with the strong typing? Thanks ~sean On Wed, Jul 2, 2008 at 4:29 PM, Tracy Spratt [EMAIL PROTECTED] wrote: It is a rare case that you want to use mx:Model or the default resultFormat=object. You take the performance hit for the conversion, you have no control over the conversion process (your strings that look like numbers will get converted to numbers, willy nilly) and you wind up with dynamic objects, which have an access peformance penalty. I advise using resultFormat=e4x, a result handler function, and an instance variable to hold the xmlResult. The best performance, especially in a multi-renderer DataGrid, will be if you manually convert the XML node data ino an ArrayCollection of strongly typed value objects. Tracy -- *From:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On Behalf Of *Sean Clark Hess *Sent:* Wednesday, July 02, 2008 4:05 PM *To:* flexcoders@yahoogroups.com *Subject:* Re: [flexcoders] Inspecting data from HTTPService result to an ArrayCollection Ah, got it. The mx:Model tag converts everything to a flat object. So the minute you use it, you no longer have xml. It's still easy enough to loop through though. var result:Object = myData.getItemAt(0); for (var name:String in result) { trace(name + :: + result[name]); } should output apple :: 81768 orange :: 60310 banana :: 43357 On Wed, Jul 2, 2008 at 1:46 PM, Stephen More [EMAIL PROTECTED] wrote: Here is my output: DEBUG: 2 null [object Object] CHECK : false CHECK : false Here is all the code: ?xml version=1.0? !-- charts/XMLFileToArrayCollectionDataProvider.mxml -- mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; width=100% height=100% mx:Script import mx.utils.ArrayUtil; /mx:Script mx:Model id=results source=../assets/data.xml/ mx:ArrayCollection id=myData source={ArrayUtil.toArray(results.result)} / mx:Panel title=Line Chart mx:LineChart id=chart dataProvider={myData} showDataTips=true mx:horizontalAxis mx:CategoryAxis categoryField=month/ /mx:horizontalAxis mx:series mx:LineSeries yField=banana displayName=Banana/ mx:LineSeries yField=apple displayName=Apple/ mx:LineSeries yField=orange displayName=Orange/ /mx:series /mx:LineChart mx:Button id=iconButton label=Button with Icon labelPlacement=right color=#993300 click=printMessage(event);/ mx:Script ![CDATA[ import flash.events.Event; // Event handler function to print a message // describing the selected Button control. private function printMessage(event:Event):void { //message.text += event.target.label + pressed + \n; var myXML:XML; myXML = myData.getItemAt(0) as XML; trace( DEBUG: + myData.length + + myXML ); trace( myData.getItemAt(0) ); trace(CHECK : + (myData.getItemAt(0) is XML)); trace(CHECK : + (myData.getItemAt(0) is XMLList)); } ]] /mx:Script /mx:Panel /mx:Application On Wed, Jul 2, 2008 at 3:34 PM, Sean Clark Hess [EMAIL PROTECTED]seanhess%40gmail.com wrote: What do you get when you trace myData.getItemAt(0)? That will return null if it isn't an XML. You can do this too: trace(CHECK : + (myData.getItemAt(0) is XML)); You can check to see if it is an XMLList too, but I thought looking at it, it seemed like a flat xml. On Wed, Jul 2, 2008 at 1:32 PM, Stephen More [EMAIL PROTECTED]stephen.more%40gmail.com wrote: Thats what I was thinking but when I try: var myXML:XML; myXML = myData.getItemAt(0) as XML; trace( DEBUG: + myXML ); I get DEBUG: null On Wed, Jul 2, 2008 at 2:30 PM, Sean Clark Hess [EMAIL PROTECTED]seanhess%40gmail.com wrote: Each row is an xml object... So, (myData.getItemAt(i) as XML).children() Then you could loop through the children and ask them for their name. After the as XML step you can do anything you can normally do with the XML object On Wed, Jul 2, 2008 at 12:11 PM, Stephen More [EMAIL PROTECTED]stephen.more%40gmail.com wrote: ( Example code taken from: http://livedocs.adobe.com/flex/201/html/charts_intro_108_12.html ) Here is the dataset I am trying to work with: data result month=Jan-04 apple81768/apple orange60310/orange banana43357/banana /result result month=Feb-04 apple81156/apple orange58883/orange banana49280/banana /result /data The flex code will look like this: mx:HTTPService id=srv url=../assets/data.xml useProxy=false result=myData=ArrayCollection(srv.lastResult.data.result) / How can I interrogate the ArrayCollection named myData so that it will return apple, orange, and banana ? I am not looking to get the numerical values, I want to get the xml name. -Thanks
RE: [flexcoders] Inspecting data from HTTPService result to an ArrayCollection
A DataGrid can directly consume both XMLList and XMLListCollection. Search the archives for a full discussion of DataGrid performance. Also these blog entries: http://blog.fastlanesw.com/?p=14 http://blog.fastlanesw.com/?p=14 , http://blog.fastlanesw.com/?p=16. http://blog.fastlanesw.com/?p=16. I think it was Scott who brought this issue to the attention of the community first. This really only seems to be a major factor when you have many visible itemRenderers. I still use XML a lot. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Sean Clark Hess Sent: Wednesday, July 02, 2008 6:19 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Inspecting data from HTTPService result to an ArrayCollection Tracy, can a datagrid read an xml object directly? (Like, an XMLList or XMLListCollection?) If so, why would manually converting it perform better than the original XML? Does it have something to do with the strong typing? Thanks ~sean On Wed, Jul 2, 2008 at 4:29 PM, Tracy Spratt [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: It is a rare case that you want to use mx:Model or the default resultFormat=object. You take the performance hit for the conversion, you have no control over the conversion process (your strings that look like numbers will get converted to numbers, willy nilly) and you wind up with dynamic objects, which have an access peformance penalty. I advise using resultFormat=e4x, a result handler function, and an instance variable to hold the xmlResult. The best performance, especially in a multi-renderer DataGrid, will be if you manually convert the XML node data ino an ArrayCollection of strongly typed value objects. Tracy From: flexcoders@yahoogroups.com mailto:flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders@yahoogroups.com ] On Behalf Of Sean Clark Hess Sent: Wednesday, July 02, 2008 4:05 PM To: flexcoders@yahoogroups.com mailto:flexcoders@yahoogroups.com Subject: Re: [flexcoders] Inspecting data from HTTPService result to an ArrayCollection Ah, got it. The mx:Model tag converts everything to a flat object. So the minute you use it, you no longer have xml. It's still easy enough to loop through though. var result:Object = myData.getItemAt(0); for (var name:String in result) { trace(name + :: + result[name]); } should output apple :: 81768 orange :: 60310 banana :: 43357 On Wed, Jul 2, 2008 at 1:46 PM, Stephen More [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Here is my output: DEBUG: 2 null [object Object] CHECK : false CHECK : false Here is all the code: ?xml version=1.0? !-- charts/XMLFileToArrayCollectionDataProvider.mxml -- mx:Application xmlns:mx=http://www.adobe.com/2006/mxml http://www.adobe.com/2006/mxml width=100% height=100% mx:Script import mx.utils.ArrayUtil; /mx:Script mx:Model id=results source=../assets/data.xml/ mx:ArrayCollection id=myData source={ArrayUtil.toArray(results.result)} / mx:Panel title=Line Chart mx:LineChart id=chart dataProvider={myData} showDataTips=true mx:horizontalAxis mx:CategoryAxis categoryField=month/ /mx:horizontalAxis mx:series mx:LineSeries yField=banana displayName=Banana/ mx:LineSeries yField=apple displayName=Apple/ mx:LineSeries yField=orange displayName=Orange/ /mx:series /mx:LineChart mx:Button id=iconButton label=Button with Icon labelPlacement=right color=#993300 click=printMessage(event);/ mx:Script ![CDATA[ import flash.events.Event; // Event handler function to print a message // describing the selected Button control. private function printMessage(event:Event):void { //message.text += event.target.label + pressed + \n; var myXML:XML; myXML = myData.getItemAt(0) as XML; trace( DEBUG: + myData.length + + myXML ); trace( myData.getItemAt(0) ); trace(CHECK : + (myData.getItemAt(0) is XML)); trace(CHECK : + (myData.getItemAt(0) is XMLList)); } ]] /mx:Script /mx:Panel /mx:Application On Wed, Jul 2, 2008 at 3:34 PM, Sean Clark Hess [EMAIL PROTECTED] mailto:seanhess%40gmail.com wrote: What do you get when you trace myData.getItemAt(0)? That will return null if it isn't an XML. You can do this too: trace(CHECK : + (myData.getItemAt(0) is XML)); You can check to see if it is an XMLList too, but I thought looking at it, it seemed like a flat xml. On Wed, Jul 2, 2008 at 1:32 PM, Stephen More [EMAIL PROTECTED] mailto:stephen.more%40gmail.com wrote: Thats what I was thinking but when I try: var myXML:XML; myXML = myData.getItemAt(0) as XML; trace( DEBUG: + myXML ); I get DEBUG: null On Wed, Jul 2, 2008 at 2:30 PM, Sean Clark Hess [EMAIL PROTECTED] mailto:seanhess%40gmail.com wrote: Each row is an xml object... So, (myData.getItemAt(i) as XML).children() Then you could loop through the children and ask them for their name. After the as XML step you can do anything you can normally