How about this:

 

var smallCollection:ArrayCollection = new
ArrayCollection(bigCollection.source.splice(0, 10));

 

Or somethinglike:

 

var smallCollection:ArrayCollection = new ArrayCollection();

...

smallCollection.source = bigCollection.source.splice(0, 10);

trace(smallCollection.length); // 10

 

 

Peter

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Nayan Savla
Sent: Monday, March 03, 2008 4: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]
<mailto:tspratt%40lariatinc.com> > 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:flexcoders%40yahoogroups.com>
[mailto:[email protected] <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of Nayan Savla
> Sent: Monday, March 03, 2008 4:00 PM
> To: [email protected] <mailto:flexcoders%40yahoogroups.com> 
> 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
>
> 

 

Reply via email to