Mouse51180
06-13-2008, 05:58 PM
I am having issues with a roll over animated button script. The working script was based off an Adobe animated button turotial I found.
This is what the script does. It’s a simple rollover animation. There is a button labeled RedButton_mc. It looks like a button and when you put your mouse on it a small animation happens. When you take your mouse off of it the animation reverses.
The top function says to start the first animation (labeled _over) when the mouse is over the button
The bottom function says to start the reverse animation (labeled _out) when the mouse leaves the button area.
Here is the working script:
RedButton_mc.addEventListener(MouseEvent.MOUSE_OVE R, buttonOverHandler);
function buttonOverHandler(MouseEvent) : void {
RedButton_mc.gotoAndPlay("_over");
}
RedButton_mc.addEventListener(MouseEvent.MOUSE_OUT , buttonOutHandler);
function buttonOutHandler(MouseEvent) : void {
RedButton_mc.gotoAndPlay("_out");
}
My problem is that I have more different colored buttons and I am getting errors when I add to this code. All the other buttons have the same names just the Red might say Yellow, or Blue or Green. Here are some of the codes I have tried and the errors I have gotten. The below code are to just get the Blue Button’s “_over” animation to start playing. Below are the 3 ways I have tried to adjust the code to get it working.
Any help is appreciated.
Code attempt 1:
1 RedButton_mc.addEventListener(MouseEvent.MOUSE_OVE R, buttonOverHandler);
2 function buttonOverHandler(MouseEvent) : void {
3 RedButton_mc.gotoAndPlay("_over");
4 }
5
6 RedButton_mc.addEventListener(MouseEvent.MOUSE_OUT , buttonOutHandler);
7 function buttonOutHandler(MouseEvent) : void {
8 RedButton_mc.gotoAndPlay("_out");
9 }
10
11 BlueButton_mc.addEventListener(MouseEvent.MOUSE_OV ER, buttonOverHandler);
12 function buttonOverHandler(MouseEvent) : void {
13 BlueButton_mc.gotoAndPlay("_over");
14 }
Error:
Duplicate function definition on line 12
Code attempt 2:
1 RedButton_mc.addEventListener(MouseEvent.MOUSE_OVE R, buttonOverHandler);
2 function buttonOverHandler(MouseEvent) : void {
3 RedButton_mc.gotoAndPlay("_over");
4 }
5
6 RedButton_mc.addEventListener(MouseEvent.MOUSE_OUT , buttonOutHandler);
7 function buttonOutHandler(MouseEvent) : void {
8 RedButton_mc.gotoAndPlay("_out");
9 }
10
11 BlueButton_mc.addEventListener(MouseEvent.MOUSE_OV ER, buttonOverHandler);
12 BlueButton_mc.gotoAndPlay("_over");
Error:
Access of undefined property BlueButton_mc. Lines 11 and 12
Code attempt 3:
1 RedButton_mc.addEventListener(MouseEvent.MOUSE_OVE R, buttonOverHandler);
2 BlueButton_mc.addEventListener(MouseEvent.MOUSE_OV ER, buttonOverHandler);
3 function buttonOverHandler(MouseEvent) : void {
4 RedButton_mc.gotoAndPlay("_over");
5 BlueButton_mc.gotoAndPlay("_over");
6 }
7
8 RedButton_mc.addEventListener(MouseEvent.MOUSE_OUT , buttonOutHandler);
9 function buttonOutHandler(MouseEvent) : void {
10 RedButton_mc.gotoAndPlay("_out");
11 }
Error:
Access of undefined property BlueButton_mc. Lines 2 and 5
This is what the script does. It’s a simple rollover animation. There is a button labeled RedButton_mc. It looks like a button and when you put your mouse on it a small animation happens. When you take your mouse off of it the animation reverses.
The top function says to start the first animation (labeled _over) when the mouse is over the button
The bottom function says to start the reverse animation (labeled _out) when the mouse leaves the button area.
Here is the working script:
RedButton_mc.addEventListener(MouseEvent.MOUSE_OVE R, buttonOverHandler);
function buttonOverHandler(MouseEvent) : void {
RedButton_mc.gotoAndPlay("_over");
}
RedButton_mc.addEventListener(MouseEvent.MOUSE_OUT , buttonOutHandler);
function buttonOutHandler(MouseEvent) : void {
RedButton_mc.gotoAndPlay("_out");
}
My problem is that I have more different colored buttons and I am getting errors when I add to this code. All the other buttons have the same names just the Red might say Yellow, or Blue or Green. Here are some of the codes I have tried and the errors I have gotten. The below code are to just get the Blue Button’s “_over” animation to start playing. Below are the 3 ways I have tried to adjust the code to get it working.
Any help is appreciated.
Code attempt 1:
1 RedButton_mc.addEventListener(MouseEvent.MOUSE_OVE R, buttonOverHandler);
2 function buttonOverHandler(MouseEvent) : void {
3 RedButton_mc.gotoAndPlay("_over");
4 }
5
6 RedButton_mc.addEventListener(MouseEvent.MOUSE_OUT , buttonOutHandler);
7 function buttonOutHandler(MouseEvent) : void {
8 RedButton_mc.gotoAndPlay("_out");
9 }
10
11 BlueButton_mc.addEventListener(MouseEvent.MOUSE_OV ER, buttonOverHandler);
12 function buttonOverHandler(MouseEvent) : void {
13 BlueButton_mc.gotoAndPlay("_over");
14 }
Error:
Duplicate function definition on line 12
Code attempt 2:
1 RedButton_mc.addEventListener(MouseEvent.MOUSE_OVE R, buttonOverHandler);
2 function buttonOverHandler(MouseEvent) : void {
3 RedButton_mc.gotoAndPlay("_over");
4 }
5
6 RedButton_mc.addEventListener(MouseEvent.MOUSE_OUT , buttonOutHandler);
7 function buttonOutHandler(MouseEvent) : void {
8 RedButton_mc.gotoAndPlay("_out");
9 }
10
11 BlueButton_mc.addEventListener(MouseEvent.MOUSE_OV ER, buttonOverHandler);
12 BlueButton_mc.gotoAndPlay("_over");
Error:
Access of undefined property BlueButton_mc. Lines 11 and 12
Code attempt 3:
1 RedButton_mc.addEventListener(MouseEvent.MOUSE_OVE R, buttonOverHandler);
2 BlueButton_mc.addEventListener(MouseEvent.MOUSE_OV ER, buttonOverHandler);
3 function buttonOverHandler(MouseEvent) : void {
4 RedButton_mc.gotoAndPlay("_over");
5 BlueButton_mc.gotoAndPlay("_over");
6 }
7
8 RedButton_mc.addEventListener(MouseEvent.MOUSE_OUT , buttonOutHandler);
9 function buttonOutHandler(MouseEvent) : void {
10 RedButton_mc.gotoAndPlay("_out");
11 }
Error:
Access of undefined property BlueButton_mc. Lines 2 and 5