Press Button - Keep Button ColorWhen you press on a link in a browser the color changes (if it should) and then stays changed to indicate that the link was pressed. Usually in Flash this is not possible but with actionscript we can achieve that. Here is the actionscript. First you create one or more buttons for a menu or whatever but they have to be movieclips. //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){ //we give the button a new color when the mouse is over it... myButton.onRollOver=function(){ myButton.newColor(0xFF0000); } //...and back to the original color when on Rollout. "newColor" is a //function we define (see further down). if(_global.aPressed==undefined){ myButton.onRollOut=function(){ myButton.newColor(0x000000); } //if the button was pressed, we also give a new color, grey in this case //but only if the global var aPressed has a value. }else if(_global.aPressed==frame){ myButton.newColor(0xBDC6DE); } //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(0xBDC6DE); //This function here will override the above onRollOut function. myButton.onRollOut=function(){ myButton.newColor(0xBDC6DE); } } } //we repeat all this for the other buttons. I tried a shortcut but that did not //work so far. function changeColor2(myButton,bPressed,frame){ myButton.onRollOver=function(){ myButton.newColor(0xFF0000); } if(_global.bPressed==undefined){ myButton.onRollOut=function(){ myButton.newColor(0x000000); } }else if(_global.bPressed==frame){ myButton.newColor(0xBDC6DE); } myButton.onPress=function(){ _global.bPressed=frame; gotoAndPlay(frame); myButton.newColor(0xBDC6DE); myButton.onRollOut=function(){ myButton.newColor(0xBDC6DE); } } } function changeColor3(myButton,cPressed,frame){ myButton.onRollOver=function(){ myButton.newColor(0xFF0000); } if(_global.cPressed==undefined){ myButton.onRollOut=function(){ myButton.newColor(0x000000); } }else if(_global.cPressed==frame){ myButton.newColor(0xBDC6DE); } myButton.onPress=function(){ _global.cPressed=frame; gotoAndPlay(frame); myButton.newColor(0xBDC6DE); myButton.onRollOut=function(){ myButton.newColor(0xBDC6DE); } } } //executing all the button functions changeColor1(myBut1,pressed1,2); changeColor2(myBut2,pressed2,3); changeColor3(myBut3,pressed3,4); //we also have a menu button to go back to the menu. menuBut.onPress=function(){ gotoAndPlay(1); } //this is the function to change the button color. MovieClip.prototype.newColor=function(myColor){ newCol=new Color(this); newCol.setRGB(myColor); } |