# buttonLoopScript problem

**URL:** <https://forum.kirupa.com/t/buttonloopscript-problem/294475>\
**Category:** flash\
**Created:** [August 14, 2009, 3:26pm UTC](https://forum.kirupa.com/t/buttonloopscript-problem/294475 "2009-08-14T15:26:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisribar](https://avatars.discourse-cdn.com/v4/letter/c/5fc32e/32.png) [@chrisribar](https://forum.kirupa.com/u/chrisribar)\
**Post date:** [August 14, 2009, 3:26pm UTC](https://forum.kirupa.com/t/buttonloopscript-problem/294475/1 "2009-08-14T15:26:25Z")

</div>

Attached is my .fla file for flash cs3. What I want to happen is for the first button to automatically become activated and play the PageIn0 clip upon playing. Can anyone help me out? Thanks!

CODE:

currentButton = null;  
firstButtonPress = true;

function buttonCheck(n) {  
buttonCollection[‘b’+n].onRollOver = function() {  
this.gotoAndPlay(‘in’);  
};  
buttonCollection[‘b’+n].onRollOut = function() {  
this.gotoAndPlay(‘out’);  
};  
buttonCollection[‘b’+n].onPress = function() {  
this.gotoAndPlay(‘press’);  
this.enabled = false;  
buttonPressed(n);  
};  
}

function buttonPressed(n) {  
if (firstButtonPress == true) {  
mainClip.gotoAndPlay(“pageIn”+n);  
firstButtonPress = false;  
} else {  
buttonCollection[‘b’+currentButton].gotoAndPlay(‘out’);  
buttonCollection[‘b’+currentButton].enabled = true;  
mainClip.gotoAndPlay(“pageOut”+currentButton);  
}  
currentButton = n;  
trace("you pressed button "+n);  
}

for (z=0; z\<5; z++) {  
buttonCheck(z);  
}
