# Table of Contents button array needs to respond to a "next" button

**URL:** <https://forum.kirupa.com/t/table-of-contents-button-array-needs-to-respond-to-a-next-button/325310>\
**Category:** flash\
**Created:** [October 8, 2011, 11:47pm UTC](https://forum.kirupa.com/t/table-of-contents-button-array-needs-to-respond-to-a-next-button/325310 "2011-10-08T23:47:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sslat](https://avatars.discourse-cdn.com/v4/letter/s/77aa72/32.png) [@sslat](https://forum.kirupa.com/u/sslat)\
**Post date:** [October 8, 2011, 11:47pm UTC](https://forum.kirupa.com/t/table-of-contents-button-array-needs-to-respond-to-a-next-button/325310/1 "2011-10-08T23:47:31Z")

</div>

I have an array of movieclip buttons that is a table of contents for a module. I am using a loop function to maintain their down state when clicked. All of the event listeners for each content heading in the table of contents are coded outside the loop and each one loads an external swf file (also in an array). I also have “next” and “previous” buttons that advance the external swf files being loaded but I also want the button array to move forward and highlight the next section. How do I advance the button array outside its loop function? I appreciate any insight.

var buttonsArray:Array = [toc\_mc.intro\_mc,toc\_mc.gen\_mc,toc\_mc.dist\_mc,toc\_mc.hered\_mc,etc…];  
var i:int;  
function setButtons():void {  
for (i=0; i\<buttonsArray.length; i++) {

buttonsArray\*.id = i;  
buttonsArray\*.buttonMode = true;  
buttonsArray\*.mouseChildren = false;  
buttonsArray\*.mouseEnabled = true;  
buttonsArray\*.addEventListener(MouseEvent.ROLL\_OVER,playOver);  
buttonsArray\*.addEventListener(MouseEvent.ROLL\_OUT,playOut);  
buttonsArray\*.addEventListener(MouseEvent.CLICK,doClick);  
}  
}  
function playOver(event:MouseEvent):void {  
event.currentTarget.gotoAndStop(2);  
}  
function playOut(event:MouseEvent):void {  
event.currentTarget.gotoAndStop(1);  
}  
function doClick(event:MouseEvent):void{  
var currentBtn:int = event.currentTarget.id;  
setSelectedBtn(currentBtn);  
}  
function setSelectedBtn(id:int):void{  
for (var i:int=0; i\< buttonsArray.length; i++) {  
if (id == i) {  
buttonsArray\*.gotoAndStop(3);  
buttonsArray\*.buttonMode = false;  
buttonsArray\*.mouseEnabled = false;  
buttonsArray\*.removeEventListener(MouseEvent.ROLL\_OVER,playOver);  
buttonsArray\*.removeEventListener(MouseEvent.ROLL\_OUT,playOut);  
buttonsArray\*.removeEventListener(MouseEvent.CLICK,doClick);  
} else {  
if(buttonsArray\*.currentFrame ==3){  
buttonsArray\*.gotoAndStop(1);  
}  
buttonsArray\*.buttonMode = true;  
buttonsArray\*.mouseEnabled = true;  
buttonsArray\*.addEventListener(MouseEvent.ROLL\_OVER,playOver);  
buttonsArray\*.addEventListener(MouseEvent.ROLL\_OUT,playOut);  
buttonsArray\*.addEventListener(MouseEvent.CLICK,doClick);  
}  
}  
}

setButtons();

medPlay\_mc.prev\_btn.addEventListener(MouseEvent.CLICK, prev\_onClick);  
medPlay\_mc.next\_btn.addEventListener(MouseEvent.CLICK, next\_onClick);

function next\_onClick(event:MouseEvent):void {

//current index refers to the swf file array

currentIndex++;  
removeChild(loader);  
modBan\_mc.visible=false;  
if(currentIndex \> urlArray.length - 1) {  
currentIndex = 0;  
}  
loader.load(new URLRequest(urlArray[currentIndex]));  
addChild(loader);  
addChild(toc\_mc);  
addChild(medPlay\_mc);  
}

function prev\_onClick(event:MouseEvent):void {  
currentIndex–;  
removeChild(loader);  
if(currentIndex \< 0) {  
currentIndex = urlArray.length - 1;  
}  
loader.load(new URLRequest(urlArray[currentIndex]));  
addChild(loader);  
addChild(toc\_mc);  
addChild(medPlay\_mc);  
}
