cool, found out what i was doing wrong,
testList.property.(@name == "account_status")[EMAIL PROTECTED] //not the
correct node
had to use,
testList.(@name == "account_status")[EMAIL PROTECTED]
in this case there is name, value attributes for every node, will keep
the other way in mind as well.
thanks once again.
Nayan
On Tue, Mar 4, 2008 at 4:33 PM, Tracy Spratt <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
>
>
>
>
> NO FOR LOOPS with e4x! Well, hardly ever anyway. You access serach on
> attributes like this:
>
>
>
> var xlFound:XMLList = myXML.property.(@name=="username"); //*all e4x
> expressions return an xmllist*
>
> var xmlFound:XML = xlFound[0]; //if we know there wil be only one node
> found, get it
>
> trace([EMAIL PROTECTED]); //will show 'me'
>
>
>
> Note, if you are filtering on an attribute value, and not all nodes have
> that attribute, you will get an error with the above syntax. To avoid that
> I always use this form:
>
> var xlFound:XMLList = myXML.property.(attribute("name")=="username"); //*all
> e4x expressions return an xmllist*
>
>
>
> That format also lends itself to dynamic expressions, since "name" or
> whatever can be a variable containing the attribute name.
>
>
>
> Tracy
>
>
>
> ________________________________
>
>
> From: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf Of Nayan Savla
> Sent: Tuesday, March 04, 2008 2:36 PM
>
>
> To: [email protected]
> Subject: Re: [flexcoders] extracting items from array collection getItemAt
> doesn't work
>
>
>
>
>
>
>
>
> Tracy,
>
> I see your point in using e4x expressions and the performance hit i
> take just to use dynamic nested structure. It won't take much for me
> to convert my code to make use of e4x functionality.
>
> I have started doing that and i couldn't find a way to search and
> match attributes, for eg.
>
> <property name="username" value="me"/>
> <property name="account_status" value="active"/>
> <property name="session_id" value="h5142ner7vq5oitqcvi0"/>
> <property name="salt" value="e9d6b14092524122254"/>
> <property name="signup_date" value="2007-08-16"/>
> <property name="now" value="2008-03-04"/>
> <property name="first_name" value="Nayan"/>
>
> how do i retrieve the value attribute associated with the attribute
> name="username" ?
>
> I know i could always run a for loop and then store the data as
> name-value pairs in an object but i want to know if there is a way
> doing it using the xmllist class.
>
> testList.property.(@name == "account_status")[EMAIL PROTECTED]
>
> something like this, it will be really helpful since something like
> this would be the beginning.
>
> thanks for all your help.
> Nayan
>
> On Mon, Mar 3, 2008 at 7:12 PM, Tracy Spratt <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > As I suspected, you are not using xml:
> >
> > "I haven't set the resultformat of my httpservice, its
> > using the default format."
> >
> >
> >
> > The default resultFormat is to have Flex convert your XML into a nested
> > dynamic object structure. This converts XMLLists into arrays, among other
> > things.
> >
> >
> >
> > Generally this is bad. There is no benefit to a nested dynamic structure
> > over XML and in fact, there are many reasons to use XML, e4x expressions
> > being chief among those reasons. Your current situation is actually the
> > worst of both worlds: you lose the e4x functionality and suffer from the
> > performance hits of non-strongly-typed data access.
> >
> >
> >
> > The only reason to stay on this course is laziness.
> >
> >
> >
> > If you absolutely insist, I will tell you how to get a ArrayCollection
> out
> > of the mess you have, but it would be a mistake. Two better options are:
> >
> > * Use XMLListCollection
> >
> > * Use e4x and convert your XMLList into an ArrayCollection of strongly
> typed
> > data objects. This is a manual process of looping over the XMLList and
> > building each object and then adding it to the ArrayCollection
> >
> >
> >
> >
> >
> > Tracy
> >
> >
> >
> > ________________________________
> >
> >
> > From: [email protected] [mailto:[EMAIL PROTECTED] On
> > Behalf Of Nayan Savla
> > Sent: Monday, March 03, 2008 7:11 PM
> > To: [email protected]
> > Subject: Re: [flexcoders] extracting items from array collection
> getItemAt
> > doesn't work
> >
> >
> >
> >
> >
> >
> > the url parameter for the httpService is a XML file so yes,
> >
> > var bigCollection:ArrayCollection = data.result.myBigList as
> > ArrayCollection; //I am reading an xml file.
> >
> > this is true. I haven't set the resultformat of my httpservice, its
> > using the default format.
> >
> > Also in the debugger i see that the variable bigCollection stores the
> > xml file as a object list and as i mentioned i can easily extract the
> > array from this using,
> >
> > var smallCollection:Array = bigCollection.toArray().slice(0,10);
> > //this works just fine.
> >
> > the data in this array is as expected, What i don't understand is why
> > i can't convert it into an ArrayCollection.
> >
> > Nayan
> >
> > On Mon, Mar 3, 2008 at 3:39 PM, Tracy Spratt <[EMAIL PROTECTED]>
> wrote:
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > Have you verified this line below? It raises doubts:
> > >
> > >
> > > var bigCollection:ArrayCollection = data.result.myBigList as
> > > ArrayCollection; //I am reading an xml file.
> > >
> > >
> > >
> > > First, XML will only yield an XMLList and you cannot cast an XMLList to
> > an
> > > ArrayCollection.
> > >
> > >
> > >
> > > I suspect you may not have xml as you think, but instead a nested
> object
> > > structure. It depends on how you are getting your data. If that is so,
> it
> > > is not a good way to do it. Have you set your resultFormat="e4x"?
> > >
> > >
> > >
> > > If you are getting XML from the server, why not use XMLListCollection?
> > >
> > >
> > >
> > > If you do not want to use that, you should convert your XMLList into an
> > > ArrayCollection of strongly typed data objects. This is a manual
> process
> > of
> > > looping over the XMLList and building each object and then adding it to
> > the
> > > AC.
> > >
> > >
> > >
> > > Tracy
> > >
> > >
> > >
> > > ________________________________
> > >
> > >
> > > From: [email protected] [mailto:[EMAIL PROTECTED] On
> > > Behalf Of Nayan Savla
> > > Sent: Monday, March 03, 2008 4:00 PM
> > > To: [email protected]
> > > Subject: [flexcoders] extracting items from array collection getItemAt
> > > doesn't work
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > Hi All,
> > >
> > > I am trying to get data from an ArrayCollection and i tried various
> > > things without any luck.
> > >
> > > this is the code,
> > >
> > > var bigCollection:ArrayCollection = data.result.myBigList as
> > > ArrayCollection; //I am reading an xml file.
> > >
> > > 1) var smallCollection:ArrayCollection =
> > > bigCollection.getItemAt(0,10); //i believe this is the correct method
> > > but doesn't work
> > >
> > > 2) var smallCollection:ArrayCollection =
> > > bigCollection.toArray().slice(0,10) as ArrayCollection; //this returns
> > > null
> > >
> > > 3) var smallCollection:Array = bigCollection.toArray().slice(0,10);
> > > //this works just fine.
> > >
> > > any ideas why i can't just use the second statement, please ignore my
> > > knowledge of flex if i am missing something fundamental.
> > >
> > > thanks
> > > Nayan
> > >
> > >
> >
> >
>
>