# AS2 - issues referencing array index

**URL:** <https://forum.kirupa.com/t/as2-issues-referencing-array-index/324526>\
**Category:** flash\
**Created:** [August 25, 2011, 1:09pm UTC](https://forum.kirupa.com/t/as2-issues-referencing-array-index/324526 "2011-08-25T13:09:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![louisHD](https://avatars.discourse-cdn.com/v4/letter/l/ee59a6/32.png) [@louisHD](https://forum.kirupa.com/u/louisHD)\
**Post date:** [August 25, 2011, 1:09pm UTC](https://forum.kirupa.com/t/as2-issues-referencing-array-index/324526/1 "2011-08-25T13:09:27Z")

</div>

Hi all,

I have three placeholder images, the contents of which are populated by an array (“galleryArray”).

These three placeholders are titled “placeholderLeft”, “placeholderCentre” and “placeholderRight”.

the contents of “placeholderLeft” will be: “galleryArray[n-1]”  
the contents of “placeholderCentre” will be: “galleryArray[n]”  
the contents of “placeholderRight” will be: “galleryArray[n+1]”

basically, on clicking “placeholderRight”, I’m trying to increase the value of “n” by 1. By clicking placeholderLeft I’m trying to get the value of “n” to decrease by 1.

I have successfully done this within for loops and functions but can’t figure out how to extract & update the new value of the “n” variable .

Any help would be greatly appreciated, code below (function version):  
_as you will see below, the array length is calculated by “galleryNo”, I will need the value of “n” to reset to (galleryNo/galleryNo) if it exceeds this number or change to “galleryNo” if it drops below 0 - any tips on this would also be greatly appreciated._

[LEFT][COLOR=#993300]var[/COLOR] galleryArray:[COLOR=#993300]Array[/COLOR] = [COLOR=#993300]new[/COLOR] [COLOR=#993300]Array[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000FF]“mc\_01”[/COLOR],[COLOR=#0000FF]“mc\_02”[/COLOR], [COLOR=#0000FF]“mc\_03”[/COLOR], [COLOR=#0000FF]“mc\_04”[/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#993300]var[/COLOR] galleryNo:[COLOR=#993300]Number[/COLOR] = galleryArray.[COLOR=#993300]length[/COLOR]  
[COLOR=#993300]var[/COLOR] n : [COLOR=#993300]Number[/COLOR]= galleryNo/galleryNo; [COLOR=#993300]

this[/COLOR].[COLOR=#993300]attachMovie[/COLOR][COLOR=#000000]([/COLOR]galleryArray[COLOR=#000000][[/COLOR]COLOR=#000000[/COLOR][COLOR=#000000]][/COLOR], [COLOR=#0000FF]“placeholderLeft”[/COLOR], [COLOR=#000000]1[/COLOR][COLOR=#000000])[/COLOR]; placeholderLeft.[COLOR=#993300]\_x[/COLOR] = [COLOR=#000000]0[/COLOR];  
placeholderLeft.[COLOR=#993300]\_y[/COLOR] = [COLOR=#993300]Stage[/COLOR].[COLOR=#993300]height[/COLOR]/[COLOR=#000000]2[/COLOR];

[COLOR=#993300]this[/COLOR].[COLOR=#993300]attachMovie[/COLOR][COLOR=#000000]([/COLOR]galleryArray[COLOR=#000000][[/COLOR]COLOR=#000000[/COLOR][COLOR=#000000]][/COLOR], [COLOR=#0000FF]“placeholderCentre”[/COLOR], [COLOR=#000000]2[/COLOR][COLOR=#000000])[/COLOR]; placeholderCentre.[COLOR=#993300]\_x[/COLOR] = [COLOR=#993300]Stage[/COLOR].[COLOR=#993300]width[/COLOR]/[COLOR=#000000]2[/COLOR];  
placeholderCentre.[COLOR=#993300]\_y[/COLOR] = [COLOR=#993300]Stage[/COLOR].[COLOR=#993300]height[/COLOR]/[COLOR=#000000]2[/COLOR];

[COLOR=#993300]this[/COLOR].[COLOR=#993300]attachMovie[/COLOR][COLOR=#000000]([/COLOR]galleryArray[COLOR=#000000][[/COLOR]n+[COLOR=#000000]1[/COLOR][COLOR=#000000]][/COLOR], [COLOR=#0000FF]“placeholderRight”[/COLOR], [COLOR=#000000]3[/COLOR][COLOR=#000000])[/COLOR]; placeholderRight.[COLOR=#993300]\_x[/COLOR] = [COLOR=#993300]Stage[/COLOR].[COLOR=#993300]width[/COLOR];  
placeholderRight.[COLOR=#993300]\_y[/COLOR] = [COLOR=#993300]Stage[/COLOR].[COLOR=#993300]height[/COLOR]/[COLOR=#000000]2[/COLOR];

[COLOR=#993300]trace[/COLOR] COLOR=#000000[/COLOR];

placeholderRight.[COLOR=#993300]onRelease[/COLOR] = [COLOR=#993300]function[/COLOR]COLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR] [COLOR=#993300]  
\_root[/COLOR].[COLOR=#000000]n[/COLOR] ++;  
[COLOR=#993300]trace[/COLOR] COLOR=#000000[/COLOR]; [COLOR=#000000]  
}[/COLOR]

placeholderLeft.[COLOR=#993300]onRelease[/COLOR] = [COLOR=#993300]function[/COLOR]COLOR=#000000[/COLOR][COLOR=#000000]{  
[/COLOR] [COLOR=#993300]\_root[/COLOR].[COLOR=#000000]n[/COLOR] --; [COLOR=#993300]  
trace[/COLOR] COLOR=#000000[/COLOR]; [COLOR=#000000]  
}[/COLOR]

[/LEFT]

Thanks in advance!
