Hi all,
I have 4 'button' movieclips and 4 other movieclips, all within the same parent movieclip.
The buttons are:
home_btn
service_btn
company_btn
contact_btn
The movieclips are:
subnav1 (associated with home_btn)
subnav2 (associated with service_btn)
subnav3 (associated with company_btn)
subnav4 (associated with contact_btn)
What I want to do is to show the appropriate associated subnav movieclip when the related 'button' movieclip is clicked. However, every other subnav moviecclip must be hidden and only the correct one shown. This is the script I have so far... which works to some extent, but more on that in a min.
This code is on frame 1 of a layer.
ActionScript Code:
home_btn.onRollOver = function() {
home_btn.gotoAndPlay(1);
}
home_btn.onRollOut = function() {
home_btn.gotoAndPlay(7);
}
home_btn.onMouseDown = function() {
changeNav("subnav1");
}
//this is for service button
service_btn.onRollOver = function() {
service_btn.gotoAndPlay(1);
}
service_btn.onRollOut = function() {
service_btn.gotoAndPlay(7);
}
service_btn.onMouseDown = function() {
changeNav("subnav2");
}
//this is for company button
company_btn.onRollOver = function() {
company_btn.gotoAndPlay(1);
}
company_btn.onRollOut = function() {
company_btn.gotoAndPlay(7);
}
company_btn.onMouseDown = function() {
changeNav("subnav3");
}
//this is for contact button
contact_btn.onRollOver = function() {
contact_btn.gotoAndPlay(1);
}
contact_btn.onRollOut = function() {
contact_btn.gotoAndPlay(7);
}
contact_btn.onMouseDown = function() {
changeNav("subnav4");
}
This code is on frame 1 of a different layer.
ActionScript Code:
#include "lmc_tween.as"
subnav1._visible = false;
subnav1._alpha = 0;
subnav2._visible = true;
subnav2._alpha = 100;
subnav3._visible = false;
subnav3._alpha = 0;
subnav4._visible = false;
subnav4._alpha = 0;
//set initial variables
_global.oldpage = "subnav2";
/*************** PAGE CHANGE FUNCTIONS *******************/
//set page change function
_global.changeNav = function(newpage) {
if (newpage != oldpage) {
_global.pagetochange = newpage;
trace("The oldpage is: " + oldpage);
trace("The newpage is: " + newpage);
_root.navBar[oldpage].alphaTo(0, 1.5, "easeInOutQuad");
/*_root.navBar[oldpage]._visible = false;*/
_root.navBar[pagetochange]._alpha=0;
_root.navBar[pagetochange]._visible = true;
_root.navBar[pagetochange].alphaTo(100, 1.5, "easeInOutQuad");
oldpage = newpage;
} else if (newpage == oldpage) {
stop();
trace("page already selected!");
trace("-----------");
}
}
Now, the problem is that whenever I click on any one 'button' movieclip, the function seems to run for every button. The traced output looks like this:
The oldpage is: subnav2
The newpage is: subnav4
The oldpage is: subnav4
The newpage is: subnav3
The oldpage is: subnav3
The newpage is: subnav2
The oldpage is: subnav2
The newpage is: subnav1
However, if I delete the code for all but one 'button' movieclip, it works as it should. But with the code there for each button in the first code block above, I get the wrong result. Anyone know why this is happening?
Thanks for the help in advance!
-Josh