# Array Question is AS3

**URL:** <https://forum.kirupa.com/t/array-question-is-as3/300173>\
**Category:** flash\
**Created:** [November 17, 2009, 4:23am UTC](https://forum.kirupa.com/t/array-question-is-as3/300173 "2009-11-17T04:23:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kratos2010](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@kratos2010](https://forum.kirupa.com/u/kratos2010)\
**Post date:** [November 17, 2009, 4:23am UTC](https://forum.kirupa.com/t/array-question-is-as3/300173/1 "2009-11-17T04:23:11Z")

</div>

Okay I wrote this code for my class project assignment, now I have to modify it so I have a next button which works fine but I need to modify it so that I have a previous button that will click backwards through the array.

Here is my code any help would be appreciated!

Thanks!

// start code here is the code

stop();

var pepsiArray: Array = [“pepsi\_images/1\_PEPSI.jpg”,  
“pepsi\_images/2\_PEPSI.jpg”,  
“pepsi\_images/3\_PEPSI.jpg”,  
“pepsi\_images/4\_PEPSI.jpg”,  
“pepsi\_images/5\_PEPSI.jpg”,  
“pepsi\_images/6\_PEPSI.jpg”];

var count = 0;

var imageLoader: Loader = new Loader();  
addChild(imageLoader);

var imageRequest: URLRequest = new URLRequest(pepsiArray[count]);

imageLoader.x = 0;  
imageLoader.y = 0;  
imageLoader.load(imageRequest);

function imageLoad(pEvent:MouseEvent):void{

```
++count;

if (count == pepsiArray.length)
{
    count = pepsiArray.length-1;
}

else

{
    imageLoader.unload();
    
    imageRequest.url = pepsiArray[count];
    imageLoader.x = 0;
    imageLoader.x = 0;
    imageLoader.load(imageRequest);
}

```

}

btn\_next.addEventListener(MouseEvent.CLICK, imageLoad);

// end code here
