When working with graphical interfaces there are many times we want to show something can happen, but currently not available. One way we do this is by removing opacity, or dimming. In this example we have two buttons named “btn_button1″ and “btn_button2″. When the user clicks on one button it becomes unavailable, the other becomes available, and vice versa.
Understanding the code
We only want one button to work at the beginning, so we disable button 2 and dim it.
btn_button2._alpha = 50;
When button 1 is pushed
Disable button 1
Dim button 1
Enable and show button 2
Do the same, but in reverse, for button 2
btn_button2.enabled = false;
btn_button2._alpha = 50;
btn_button1.enabled = true;
btn_button1._alpha = 100;
};
Actions
Place this code in the actions keyframe where your buttons are on stage.
btn_button2._alpha = 50;
btn_button1.onRelease = function() {
btn_button1.enabled = false;
btn_button1._alpha = 50;
btn_button2.enabled = true;
btn_button2._alpha = 100;
};
btn_button2.onRelease = function() {
btn_button2.enabled = false;
btn_button2._alpha = 50;
btn_button1.enabled = true;
btn_button1._alpha = 100;
};
