I figure that this code can be reduced with a for statement, but I can’t figure it out. Here is my code, and below that is my attempt.
On the stage I have 6 movieclips named nav1_ani, nav2_ani, etc. I also have 6 buttons above them named nav1, nav2, nav3, etc.
Here is my code, here I got #5 and #6 working. Instead of duplicating all this code, is there a way to bunch it all into one “for” statement?
nav1on = false;
nav2on = false;
nav3on = false;
nav4on = false;
nav5on = false;
nav6on = false;
function clicked(button) {
for (i=1; i<7; i++) {
if (i != button) {
_root["nav"+i+"on"] = false;
_root["nav"+i+"_ani"].gotoAndStop("off");
trace("nav"+i+"on");
}
}
}
nav5.onRollOver = function() {
if (nav5on == false) {
_root.nav5_ani.gotoAndPlay("rollOver");
}
};
nav5.onRollOut = function() {
if (nav5on == false) {
_root.nav5_ani.gotoAndStop("off");
}
};
nav5.onPress = function() {
nav5_ani.gotoAndPlay("on");
nav5on = true;
_root.clicked(5);
};
nav6.onRollOver = function() {
if (nav6on == false) {
_root.nav6_ani.gotoAndPlay("rollOver");
}
};
nav6.onRollOut = function() {
if (nav6on == false) {
_root.nav6_ani.gotoAndStop("off");
}
};
nav6.onPress = function() {
nav6_ani.gotoAndPlay("on");
nav6on = true;
_root.clicked(6);
};
Here is my attempt at a “for” statement:
onLoad = function () {
for (i=1; i<7; i++) {
k = "nav"+i;
k.onRollOver = function() {
_root[k+"_ani"].gotoAndPlay("rollOver");
};
k.onRollOut = function() {
_root[k+"_ani"].gotoAndStop("off");
};
k.onPress = function() {
_root[k+"_ani"].gotoAndPlay("on");
};
}
};