Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-06-2011, 06:30 PM   #1
PBFrO
Senior Member
 
Join Date: Jan 2007
Location: Orange County, CA
Posts: 573
Default Arraycollection duplicates

Hi everyone,

I'm getting an arraycollection back from a web service and trying to delete the duplicate but add a quantity value. I can check for duplicates just fine using a dictionary, but when I try to delete the previous item in the arraycollection using
ActionScript Code:
resArray.removeItemAt(0);
I'm getting
ActionScript Code:
"RangeError: Index '1' specified is out of bounds."
. Can anyone point me in the right direction? Thanks
__________________
My Portfolio
PBFrO is offline   Reply With Quote
Old 06-06-2011, 06:56 PM   #2
Barna Biro
Senior Member
 
Barna Biro's Avatar
 
Join Date: Nov 2009
Location: LU, Switzerland
Posts: 1,410
Default

Hopefully, when you are removing items, then you are traversing the array from the back to the from and not how would normally traverse it. If you traverse it from the front to the back, then whenever you remove an item, the array gets update and the indexes change... so at one point, you will run into index values that no longer contain any elements because you have previously removed stuff.
__________________
Titus M. Plautus - Not by age but by capacity is wisdom acquired.
Barna Biro is offline   Reply With Quote
Old 06-06-2011, 07:08 PM   #3
PBFrO
Senior Member
 
Join Date: Jan 2007
Location: Orange County, CA
Posts: 573
Default

Thanks for the reply. I'm just branching into Flex, been working with Flash for a long time and trying to get used to Flex. In regards to the response, my script is breaking on the call to remove the item, so I'm not sure if the index changing is happening like you mentioned. I just tried copying the array collection into an array and gave it a shot using
ActionScript Code:
tArray.splice(i, 1);
and got the same range error. Here is the code I'm using, maybe it will help. Thanks

ActionScript Code:
for(var i:int = 0; i < resArray.length; i++) {     if(resDictionary[resArray[i].Item])     {         trace("already there");         _qty++;         if(resArray[i].Item == resArray[0].Item && i > 0)         {         //tArray.splice(i, 1);  tried this and no luck either         resArray.removeItemAt(0);         }           } }
__________________
My Portfolio
PBFrO is offline   Reply With Quote
Old 06-06-2011, 07:10 PM   #4
Barna Biro
Senior Member
 
Barna Biro's Avatar
 
Join Date: Nov 2009
Location: LU, Switzerland
Posts: 1,410
Default

It is exactly what I have explained above... instead of traversing the list from the front ( from index 0 ) you should traverse it backward ( starting from resArray.length and decrementing the value of "i", until you reach 0 ).
__________________
Titus M. Plautus - Not by age but by capacity is wisdom acquired.
Barna Biro is offline   Reply With Quote
Old 06-06-2011, 07:13 PM   #5
PBFrO
Senior Member
 
Join Date: Jan 2007
Location: Orange County, CA
Posts: 573
Default

Ah ok, I see what you mean now. Thank you so much =)
__________________
My Portfolio
PBFrO is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:46 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.