Well... here's the deal... I'm new to "For" Loops and Arrays, so I may be doing this all wrong.

When I get to the last image in my gallery's array, the final image (mImage6) stays in place, but if I click on my forward button after the final image has displayed, I get the following error message:

TypeError: Error #1010: A term is undefined and has no properties.
at Untitled_fla::MainTimeline/bClick()

Also, the back button (mBack) functions when rolled over or out and when clicked, but does not control the images in the array.

Any help would be greatly appreciated!

Here's the script I've written so far:

var aButtons:Array = new Array(bBack,bForward);
var aImages:Array = new Array(mImage0,mImage1,mImage2,mImage3,mImage4,mIma ge5,mImage6);

function btnOver(evt:Event):void {
//trace("btnOver works");
evt.target.gotoAndPlay("rollover");
//trace(evt.target.name + " rollover");
}

function btnClick(evt:Event):void {
//trace(evt.target.name + " was clicked");
gotoAndPlay(evt.target.name);
}

function btnOut(evt:Event):void {
//trace("btnOut works");
evt.target.gotoAndPlay("rollout");
//trace(evt.target.name + " rollout");
//trace(evt.target.name);
}

for (var i:Number =0; i<aButtons.length; i++) {
aButtons[i].addEventListener(MouseEvent.ROLL_OVER, btnOver);
aButtons[i].addEventListener(MouseEvent.ROLL_OUT, btnOut);
aButtons[i].addEventListener(MouseEvent.CLICK, btnClick);
aButtons[i].mouseChildren = false;
}


//trace(aImages);
//trace(aImages.length);

clearPhotos();
mImage0.visible = true;


function clearPhotos():void {
var count:Number = aImages.length;
var Index:Number;
for (var i:Number = 0; i<count; i++) {
if (aImages[i].visible == true) {
aImages[i].visible = false;
}
}
}


function bClick(evt:Event):void {
var count:Number = aImages.length;
var index:Number;
var nextImage:Number;
var prevImage:Number;
for (var i:Number = 0; i<count; i++) {
if (aImages[i].visible == true) {
nextImage = i+1;
prevImage = i-1;
/*trace ("next Image is", nextImage);
trace ("prev Image is", prevImage);*/
}
}
//trace (evt.target.name);
if (evt.target.name == "bForward") {
aImages[nextImage].visible = true;
}
if (evt.target.name == "bBack") {
aImages[prevImage].visible = true;
}
}

function loopTop(evt:Event):void {
var count:Number = aImages.length;
var index:Number;

}

bBack.addEventListener(MouseEvent.CLICK, bClick);
bForward.addEventListener(MouseEvent.CLICK, bClick);
bBack.mouseChildren = false;
bForward.mouseChildren = false;