Simplest is XMLListCollection.

Declare a var to hold the dataProvider at instance scope:

private var _xlcData:XMLListCollection;

 

Then. in your result handler (you are using a result handler, right?),
do:

private function onResult(event:ResultEvent):void

  var xmlResult:XML = XML(event.result);

  trace(xmlResult.toXMLString());  //to verify you have your data

  var xlData:XMLList = xlResult.children();  //or whatever expression
give you the row nodes you want

  trace(xlData.toXMLString());  //to verify your expression

  _xlcData = new XMLListCollection(xlData)

....

 

Bind _xlcData to the DataGridDataProvider.  Declare the column
dataFields the same way as with ArrayCollection, except if the data is
in attributes, then use dataField="@field"

 

Tracy

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of netdeep
Sent: Wednesday, September 17, 2008 3:14 PM
To: [email protected]
Subject: [flexcoders] Re: HTTPService conversion to ArrayCollection
problem

 


Yeah, you are right that when there are two or more items in the list,
the problem does 
not show up. I'm not sure how to process the results in e4x or with
XMLListCollection, 
however.

--- In [email protected] <mailto:flexcoders%40yahoogroups.com>
, "Tracy Spratt" <[EMAIL PROTECTED]> wrote:
>
> This is probably the Object vs Array problem. The player is unable to
> differentiate between an array with a single element and an object.
> Test by adding another "data" node.
> 
> 
> 
> I advise changing the default resultFormat to "e4x" and doing the
> conversion to ArrayCollection manually, instead of letting Flex do it
> for you. Or use XMLListCollection directly.
> 
> 
> 
> Accepted best practice seems to be using resultFormat="e4x" and
building
> an ArrayCollection of strongly typed VOs.
> 
> 
> 
> If you are committed to staying with the default resultFormat, you
will
> need to inspect the event.result object to determine what it contains,
> and code for the two cases.
> 
> 
> 
> Tracy
> 
> 
> 
> ________________________________
> 
> From: [email protected] <mailto:flexcoders%40yahoogroups.com>
[mailto:[email protected] <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of netdeep
> Sent: Tuesday, September 16, 2008 11:29 AM
> To: [email protected] <mailto:flexcoders%40yahoogroups.com> 
> Subject: [flexcoders] HTTPService conversion to ArrayCollection
problem
> 
> 
> 
> This is really bizarre but I have some code that was working
previously
> and now is no longer working. I 
> am using a servlet to output information in the following format:
> 
> <system>
> <data>
> <name>Channel 1</name>
> <id>Rep1</id>
> </data>
> </system>
> 
> But I am now getting a runtime error: Error #1034: Type Coercion
failed:
> cannot convert 
> mx.utils::[EMAIL PROTECTED] to mx.collections.ArrayCollection
> 
> Code:
> 
> public function initializeBrowser(evt:ResultEvent):void {
> var arr:ArrayCollection = evt.result.system.data;
> }
> 
> <mx:HTTPService id="reportsList" result="initializeBrowser(event)"
> useProxy="false"
> method="GET" url="{dbURL}"/>
>

 

Reply via email to