Makes sense, thank you for the assistance.

So, the steps suggested by yourself and others in this thread are
ultimately a better/preferred way to work with and handle xml data
when it's retrieved from an http service?


--- In [email protected], "Tracy Spratt" <[EMAIL PROTECTED]> wrote:
>
> If you are going to do this, make an ArrayCollection, you should build a
> class(value object, VO) with strongly typed public properties.
> 
>  
> 
> In the loop, "new" that class, then assign the xml node property values
> to the appropriate value object properties.  Push that VO onto a
> temporary array.  When the loop is done, wrap the array in an
> ArrayCollection.
> 
>  
> 
> Tracy
> 
>  
> 
> ________________________________
> 
> From: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf Of sdl1326
> Sent: Thursday, July 10, 2008 6:25 PM
> To: [email protected]
> Subject: [flexcoders] Re: Putting returned xml data into ArrayCollection
> using Cairngorm framwork (Command Class/Delegate Class/IResponder)
> 
>  
> 
> Ok, thanks.
> 
> So, looking at the original xml file ( below) if I want to add both
> the name and url (data) to the array collection, is this the most
> efficient way to accomplish this?
> 
> var xmlResult:XML = new XML(event.result);
> xmlImages_ac = new ArrayCollection();
> 
> // push XML to ArrayCollection
> for each(var item:XML in xmlResult.image){
> var obj:Object = new Object()
> obj.url = [EMAIL PROTECTED];
> obj.name = [EMAIL PROTECTED];
> xmlImages_ac.addItem(obj);
> }
> 
> TIA
> 
> --- In [email protected] <mailto:flexcoders%40yahoogroups.com>
> , "Josh McDonald" <dznuts@> wrote:
> >
> > That's right, because when you trace the ArrayCollection it converts
> its
> > children to String, and your nodes have no inner text, so they
> toString() as
> > "".
> > 
> > Instead of "addItem(item)", try "addItem([EMAIL PROTECTED])"
> > 
> > -Josh
> > 
> > On Fri, Jul 11, 2008 at 6:57 AM, sdl1326 <azsl1326-email@> wrote:
> > 
> > > Tracy, thanks for the very detailed reply. I changed the
> resultFormat=
> > > 'e4x'. So, I want to put the xml data into an arraycollection and am
> > > trying the following code:
> > >
> > > var xmlResult:XML = new XML(event.result);
> > >
> > > xmlImages_ac = new ArrayCollection();
> > >
> > > // push XML to ArrayCollection
> > > for each(var item:XML in xmlResult.image){
> > >
> > > xmlImages_ac.addItem(item);
> > > }
> > >
> > > trace('xmlImages_ac - ' + xmlImages_ac)
> > >
> > > For whatever reason, I can not seem to get this to work as it simply
> > > traces out:
> > >
> > > xmlImages_ac - ,,,,
> > >
> > > Can you point to where I am getting tripped up?
> > >
> > > Thanks for the assistance.
> > >
> > > --- In [email protected]
> <mailto:flexcoders%40yahoogroups.com> , "Tracy Spratt" <tspratt@> wrote:
> > > >
> > > > You have found one reason not to use resultFormat="object". 
> That result
> > > > format causes flex to convert your result data, which is xml, into
> a
> > > > tree of dynamic objects. You have no control over this
> process(, and it
> > > > has some issues, particularly that values that look like
> numbers are
> > > > converted to numbers) and it is even hard to predict. It is
> also hard
> > > > to debug, though you can use ObjUtil.toString() to see the
> contents.
> > > >
> > > >
> > > >
> > > > What is happening in your case is the "images" node becomes an
> object
> > > > containing an Array or "image" nodes. So this expression:
> > > >
> > > > result.images.image returns an Array, which you can directly
> wrap in an
> > > > ArrayCollection. I would not expect the direct assignment to
> work like
> > > > you show it, and doing it that way hides what is really
> happening. This
> > > > is more clear:
> > > >
> > > > var aResult:Array = ResultEvent( data ).result.images.image;
> > > >
> > > > trace(aResult.length); //is this what you expect
> > > >
> > > > var acImages:ArrayCollection = new ArrayCollection(aResult);
> > > >
> > > >
> > > >
> > > > Since an Array is an object, Josh's suggestion to use a for..in
> loop
> > > > would work also.
> > > >
> > > >
> > > >
> > > > I advise using resultFormat="e4x". This leaves your result data
> as XML,
> > > > so you can do:
> > > >
> > > > var xmlResult:XML = XML(ResultEvent( data ).result);
> > > >
> > > > trace(xmlResult.toXMLSTring()); //you will see your xml,
> unchanged.
> > > >
> > > >
> > > >
> > > > Now, you can use the xml directly, or use XMLList, or
> XMLListCollection,
> > > > or combinations of the three.
> > > >
> > > >
> > > >
> > > > Or, if you want, you can convert your xml, or parts thereof, into
> > > > ArrayCollections.
> > > >
> > > >
> > > >
> > > > Tracy
> > > >
> > > >
> > > >
> > > > ________________________________
> > > >
> > > > From: [email protected]
> <mailto:flexcoders%40yahoogroups.com> 
> [mailto:[email protected] <mailto:flexcoders%40yahoogroups.com>
> ] On
> > > > Behalf Of sdl1326
> > > > Sent: Thursday, July 10, 2008 12:16 PM
> > > > To: [email protected]
> <mailto:flexcoders%40yahoogroups.com> 
> > > > Subject: [flexcoders] Re: Putting returned xml data into
> ArrayCollection
> > > > using Cairngorm framwork (Command Class/Delegate Class/IResponder)
> > > >
> > > >
> > > >
> > > > Here's a sample xml that's getting loaded in via http service:
> > > >
> > > > <images duration="3000" effect="Fade" startDelay="2000">
> > > > <image name="image.jpg" url="http://www.cnn.com
> <http://www.cnn.com> 
> <http://www.cnn.com <http://www.cnn.com> > "/>
> > > > <image name="image1.jpg" url="http://www.usatoday.com
> <http://www.usatoday.com> 
> > > > <http://www.usatoday.com <http://www.usatoday.com> > " />
> > > > <image name="image2.jpg" url="http://www.msnbc.com
> <http://www.msnbc.com> 
> > > > <http://www.msnbc.com <http://www.msnbc.com> > " />
> > > > <image name="image3.jpg" url="http://www.digg.com
> <http://www.digg.com> 
> <http://www.digg.com <http://www.digg.com> >
> > > > " />
> > > > <image name="image4.jpg" url="http://www.google.com
> <http://www.google.com> 
> > > > <http://www.google.com <http://www.google.com> > " />
> > > > </images>
> > > >
> > > > If I change the code in the result handler to:
> > > >
> > > > var ac:ArrayCollection = ResultEvent( data ).result.images.image
> > > >
> > > > Then I have no issues putting it directly into an array
> collection.
> > > > It's only when I remove the (.image) and have the following:
> > > >
> > > > var ac:ArrayCollection = ResultEvent( data ).result.images
> > > >
> > > > Is when I get the coercion error. Is there any reason why I
> shouldn't
> > > > continue to put the data in an array collection via the 1st
> method?
> > > >
> > > > TIA
> > > >
> > > > --- In [email protected]
> <mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com<flexcoders%2540yahoogroups.com>
> > > >
> > > > , "Josh McDonald" <dznuts@> wrote:
> > > > >
> > > > > You're getting an ObjectProxy because you're using the
> "object" result
> > > > > format. To convert to ArrayCollection:
> > > > >
> > > > > var myArray:Array = [];
> > > > > for each (var img:* in result.images)
> > > > > {
> > > > > myArray.pish(img);
> > > > > }
> > > > >
> > > > > myCollection = new ArrayCollection(myArray);
> > > > >
> > > > > -Josh
> > > > >
> > > > > On Thu, Jul 10, 2008 at 1:31 PM, sdl1326 <azsl1326-email@>
> wrote:
> > > > >
> > > > > > Thanks for the assistance.
> > > > > >
> > > > > > I have left the resultformat blank (feel free to share why I
> > > > shouldn't
> > > > > > do this as I am always looking for best practices/advice).
> > > > However,in
> > > > > > previous projects, I have taken the return data from an http
> service
> > > > > > and immediately put it in an arraycollection in the
> resulthandler. I
> > > > > > just assumed the same could be done here when using
> Cairngorm, but
> > > > > > apparently something isn't correct. I tried your suggestion
> below
> > > > and
> > > > > > am still receiving an error:
> > > > > >
> > > > > > TypeError: Error #1034: Type Coercion failed: cannot convert
> > > > > > mx.utils::[EMAIL PROTECTED] to Array.
> > > > > >
> > > > > > Thanks in advance.
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > > --
> > > > > "Therefore, send not to know For whom the bell tolls. It tolls
> for
> > > > thee."
> > > > >
> > > > > :: Josh 'G-Funk' McDonald
> > > > > :: 0437 221 380 :: josh@
> > > > >
> > > >
> > >
> > >
> > >
> > > ------------------------------------
> > >
> > > --
> > > Flexcoders Mailing List
> > > FAQ:
> http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> <http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt> 
> > > Search Archives:
> > > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo
> <http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo> ! Groups
> > > Links
> > >
> > >
> > >
> > >
> > 
> > 
> > -- 
> > "Therefore, send not to know For whom the bell tolls. It tolls for
> thee."
> > 
> > :: Josh 'G-Funk' McDonald
> > :: 0437 221 380 :: josh@
> >
>


Reply via email to