This tutorial shows how to maintain the color of buttons indicationg the link has been pressed already like in a Browser.
Script
We first create a little menu with buttons, which have to be movieclips. We give all buttons names. We have to create three separate functions, one for each button the functions have three parameters, the buttonname, a global var to remember if the button was pressed and the frame to go to. All buttons here are movieclips.
function changeColor1(myButton, aPressed, frame) {
//when we are back in the menu, the on pressed button color should stay
if (_global.aPressed == frame) {
myButton.newColor(0xFF0000);
}
//we give the button a new color when the mouse is over it...
myButton.onRollOver = function() {
myButton.newColor(0x218429);
};
//...and back to the original color when on Rollout. "newColor" is a function we define (see further down).
myButton.onRollOut = function() {
if (_global.aPressed == undefined) {
myButton.newColor(0x000000);
} else if (_global.aPressed == frame) {
myButton.newColor(0xFF0000);
}
};
//now we define all the button functions: first when the button is pressed.
The global var will get a value now, which is the frame name or number.
The buttoncolor will change and most important on Rollout the buttoncolor will be exactly the same
unlike above when the button was not yet pressed.
myButton.onPress = function() {
_global.aPressed = frame;
gotoAndPlay(frame);
myButton.newColor(0x218429);
};
}
We repeat all this for the other buttons. Check the fla files for more details. We have to now create a function to change the button color.
MovieClip.prototype.newColor = function(myColor) {
newCol = new Color(this);
newCol.setRGB(myColor);
};
Then we execute the functions for the buttons.
changeColor1(myBut1, pressed1, 2); changeColor2(myBut2, pressed2, 3); changeColor3(myBut3, pressed3, 4);