PDA

View Full Version : Problems with For Loops


drunken_otter
03-07-2005, 01:36 AM
Im creating an online photo gallery. The problem I'm faced with involves a row of quick jump buttons (about 20 of them) where you can jump strait to the photo desired. The buttons are named btn1 - btn27. The variable 'photoCount' is the number of photos in the gallery. Im constantly updating the file, so a loop would be the way to go. The 'buttonNumber' and 'photoNumber' need to change in order to reference different file names in an array.

At the moment I'm handeling the change of the 'photoNumber' variable the long way, however I'd like to make that part of the loop:

for (j=1; j<=photoCount; j++) {
_root["btn"+j].onRelease = function() {
trace(photoNumber);
clearInterval(fwdID);
loadCheck();
currentButton.gotoAndStop('off');
currentButton = this;
this.gotoAndStop('on');
if (currentButton == btn1) {
buttonNumber = photoNumber=1;
}
if (currentButton == btn2) {
buttonNumber = photoNumber=2;
}
if (currentButton == btn3) {
buttonNumber = photoNumber=3;
}

etc...

I was originally scripting it as:
if(currentButton == ['btn'+j]){
buttonNumber = photoNumber = j
}

But that didn't work. At the moment it works but I'd like to be able to make it neater and so I don't need to change it everytime I add in a new picture.

Thanks

CyanBlue
03-07-2005, 01:44 AM
Howdy and Welcome... :)

I take that you basically want to make streamline this line of codes???

if (currentButton == btn1) {
buttonNumber = photoNumber=1;
}
if (currentButton == btn2) {
buttonNumber = photoNumber=2;
}
if (currentButton == btn3) {
buttonNumber = photoNumber=3;
}

Try this then... (Assuming currentButton is the movieClip instance name...)

buttonNumber = photoNumber = currentButton._name.substr(3, 1);