I’m trying to streamline a script I wrote to navigate a small website. I used an array to assign button functions but I feel like the rest of the functionality could be more efficient as well. Anyone?
sectionFocus = "start";
//
// Rollover function
function secondaryRoll () {
if (this.hitTest (_xmouse, _ymouse) == true) {
this.gotoAndStop ("over");
} else {
this.gotoAndStop ("off");
}
}
//
// Rollover reset
setSubnav = function () {
if (sectionFocus != "home") {
mainNav.home.onEnterFrame = secondaryRoll;
}
if (sectionFocus != "commercial") {
mainNav.commercial.onEnterFrame = secondaryRoll;
}
if (sectionFocus != "interior") {
mainNav.interior.onEnterFrame = secondaryRoll;
}
if (sectionFocus != "exterior") {
mainNav.exterior.onEnterFrame = secondaryRoll;
}
};
setSubnav ();
//
// Button Array
buttonArray = [];
buttonArray[0] = [mainNav.home, function () {
gotoAndStop ("home");
sectionFocus = "home";
setSubnav ();
}];
buttonArray[1] = [mainNav.commercial, function () {
gotoAndStop ("commercial");
sectionFocus = "commercial";
setSubnav ();
}];
buttonArray[2] = [mainNav.interior, function () {
gotoAndStop ("interior");
sectionFocus = "interior";
setSubnav ();
}];
buttonArray[3] = [mainNav.exterior, function () {
gotoAndStop ("exterior");
sectionFocus = "exterior";
setSubnav ();
}];
//
//
for (var i:Number = 0; i < buttonArray.length; i++) {
buttonArray*[0].func = buttonArray*[1];
buttonArray*[0].onPress = function () {
this.onEnterFrame = this.func;
};
buttonArray*[0].onRelease = function () {
delete this.onEnterFrame;
};
}
stop ();