This is a very simple tutorial, which shows how to use if-statements to create two functions for one button.
We need to create a button, a textfield and a movieclip. I will not go into the details of this, so check how the movieclip is organized. Let's have a look at the script.
i = 0;
myButton.onRelease = function() {
i++;
if (i == 1) {
myText = "First i = "+i;
ballMove.gotoAndPlay("start_1");
} else if (i == 2) {
myText = "Second i = "+i;
ballMove.gotoAndPlay("start_2");
i = 0;
}
};
We create a var i and give it a value, in this case 0. Then we create a button function and inside of this function we increment i. When the user clicks this button i will become 1. Now we have an if-statement. Within the if-statement we have some events executed. Now if the user presses the button again, i will have a value of 2 and the second if statement will be executed. At the same time we set i back to 0.