Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-06-2012, 12:23 PM   #1
mrNoddy
Senior Member
 
Join Date: Aug 2009
Location: London, UK
Posts: 115
Default For each item in array past point n...

Hello.

Can someone help me, I'm trying to iterate through an array and perform a function for all items past point n, for this lets say point 3. So, for each item in my array at position 4+, trace 'hello'.

Dunno why I'm struggling so much.

Thanks.
mrNoddy is offline   Reply With Quote
Old 08-06-2012, 01:08 PM   #2
midge
Member
 
Join Date: Mar 2008
Posts: 79
Default

You can loop through the array using i as a counter and start i at your target point, so for example:

ActionScript Code:
for (var i:int = 4; i < MY_ARRAY.length; i++) {    //perform function }

this will ignore the first 4 items in your array, just change the starting value of i to suit your needs
midge is offline   Reply With Quote
Old 08-06-2012, 01:59 PM   #3
mrNoddy
Senior Member
 
Join Date: Aug 2009
Location: London, UK
Posts: 115
Default

Thank you. What about if you want to get all the items before the current position?
mrNoddy is offline   Reply With Quote
Old 08-06-2012, 02:07 PM   #4
midge
Member
 
Join Date: Mar 2008
Posts: 79
Default

No problem.

You can just the loop from 0 and run a check on the index value during the loop, like:

ActionScript Code:
for (var i:int = 0; i < MY_ARRAY.length; i++) {    if(i >= 4)   {    //perform function   } }

so in the above you can perform a function on all items in your array, but also running a check to perform a function on all items indexed at 4 and above

Last edited by midge; 08-06-2012 at 02:09 PM. Reason: wasn't finished
midge is offline   Reply With Quote
Old 08-06-2012, 02:11 PM   #5
mrNoddy
Senior Member
 
Join Date: Aug 2009
Location: London, UK
Posts: 115
Default

Never mind, I simply start at 0 and use a break:

if (i == myNumber) {
break;
}

EDIT: Just saw your post, thanks again
mrNoddy is offline   Reply With Quote
Old 08-06-2012, 02:12 PM   #6
santanoa
Dual Screen Empowered
 
santanoa's Avatar
 
Join Date: Jul 2010
Location: Israel
Posts: 258
Default

Just a style note, because us programmers care so much about style...

ActionScript Code:
for (var i:int = 0; i < MY_ARRAY.length && i < 4; i++) {    //do something }

this makes your code a bit less cluttered and easier to read
santanoa is offline   Reply With Quote
Old 08-06-2012, 02:42 PM   #7
mrNoddy
Senior Member
 
Join Date: Aug 2009
Location: London, UK
Posts: 115
Default

OK, but if we are gonna clean it up I need to sort out the colour palettes. too.
mrNoddy is offline   Reply With Quote
Old 08-06-2012, 03:52 PM   #8
marlopax
Senior Member
 
Join Date: Aug 2008
Posts: 340
Default

Quote:
Originally Posted by mrNoddy View Post
OK, but if we are gonna clean it up I need to sort out the colour palettes. too.
What things you are doing with this Array?



ö
__________________
marlopax
marlopax is offline   Reply With Quote
Old 08-06-2012, 04:33 PM   #9
santanoa
Dual Screen Empowered
 
santanoa's Avatar
 
Join Date: Jul 2010
Location: Israel
Posts: 258
Default

@marlopax

@mrNoddy
santanoa 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 08:58 AM.

///
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.