Paperclip
09-04-2005, 03:43 PM
Okay, i have found a lot of people asking me how to make buttons. Well, i got annoyed enough to make this. A button tutorial cover different ways you can use buttons for your animations and games.
Simple Button:
A simple button would be a button that plays a different frame in your animation. You can be as specific as you want with adding _roots to your buttons but it is still to play a certain frame. This is the code you would use for making your button play a certain frame for your animation or game.
on (release){
gotoAndPlay(a number);
}
To make that code be correct you need to insert a number where it is blue. You must make sure though that you have that frame in your animation or game so that the button will play it. If not then you won't be playing anything at all.
For the specific parts as buttons playing _roots. Well, that is when you want to play a certain part in a movieclip or play a movieclip as a whole. To do this you need to use this code and you need to make sure you use the same instance name in your button as your movieclip. This is the code you would use to do so.
on (release){
_root.instancename.gotoAndPlay(a number);
}
For this code to work you need to make sure that you insert your movieclip's instance name where in the code it is bolded and to put in a frame number where it is blue. Make sure you test your actionscript before you test your movie because it is annoying to get a box saying you made an error and your button will do nothing at all.
Advanced Button:
The advanced button really at all isn't advanced. You can make a button as advanced as you want but it really isn't hard to do. The features that i assume are hardest to others and brings about the so called "advanceness" of it is playing different scenes and adding math features to buttons. The math features i understand because they can get confusing but i mean the scenes? Well, anyway i'll tell you all.
Making a button play a certain scene is just as easy as making the button play a certain frame. All that you add is another part of code before the frame number. Like so...
on (release){
gotoAndPlay("Scene 1", 1);
}
The bold section is what we added. All this tells the program to do is play a scene that is labeled Scene 1 and play frame 1 of that scene. Simple? Well, then why did you not tell me to put that in the simple button section? Anyway that is all you can do with that. You can't tell a button to play a scene inside of a movieclip because movieclips don't have scenes to play. You can though tell a button inside of a movieclip to play a scene on the main timeline. You would use the exact same code as above to do so. That is all for the "Scene" buttons.
Note: you can change the name of your scenes if you want to be more organized. To do so you can go up to Movie Explorer. You can find it under Windows if you don't already have it out.
For buttons useing math that is a bit more advanced and i can understand why. If you don't know what the operations mean then you can be very confused. To make a button do math or add to something you will need to have a dynamic text box with an instance name. To make a dynamic box click the text field and select dynamic text from the scroll down menu on the properties bar. Type nothing in the text box but give it an instance name of "totalMoney" without the quotes.
Now to use a button to add to your money. Make a button say with a plus sign in it. When you are done with that open up the actions panel. To make it so that everytime you release the + button you get 5 dollars you can simple put this code in.
on (release){
totalMoney += 5;
}
When you would test your movie nothing would happen when you push the button because totalMoney has no value yet. To add value to totalMoney go to frame 1 and open the actions panel. Add this code to line 1.
totalMoney = 5
Test your movie again and you should have your money going up by 5's. Now, lets add the minus money option. Make a button like a minus sign. Then open up the actions panel again to add this code to minus your money.
on (release){
totalMoney -= 5;
}
And test your movie. Now you should be able to add and subtract your money value. If you want to all out and make your own calculator make two more buttons. For your first of your two buttons make it a mulitiple sign and add this code to it.
on (release){
totalMoney *= 5;
}
That will times everything by 5. Now for the last one make a dividing sign on your button and add this code to it.
on (release){
totalMoney /= 5;
}
This is how you can make a button link to a website page:
on (release) {
geturl("http://www.awebsite.com (http://www.awebsite.com/)");
}
This will divide everything in the dynamic box by 5. Now that you are done with the buttons test your movie again and see all you can do with making decimals and huge numbers. Hope this tutorial has been useful i will add more things to it when i find them out. I think i already know that i'm missing a few things but i'm tired and i can't think of them right now. Have a great day.
Oh, and don't be afraid to click the rep button... ^_^.
Simple Button:
A simple button would be a button that plays a different frame in your animation. You can be as specific as you want with adding _roots to your buttons but it is still to play a certain frame. This is the code you would use for making your button play a certain frame for your animation or game.
on (release){
gotoAndPlay(a number);
}
To make that code be correct you need to insert a number where it is blue. You must make sure though that you have that frame in your animation or game so that the button will play it. If not then you won't be playing anything at all.
For the specific parts as buttons playing _roots. Well, that is when you want to play a certain part in a movieclip or play a movieclip as a whole. To do this you need to use this code and you need to make sure you use the same instance name in your button as your movieclip. This is the code you would use to do so.
on (release){
_root.instancename.gotoAndPlay(a number);
}
For this code to work you need to make sure that you insert your movieclip's instance name where in the code it is bolded and to put in a frame number where it is blue. Make sure you test your actionscript before you test your movie because it is annoying to get a box saying you made an error and your button will do nothing at all.
Advanced Button:
The advanced button really at all isn't advanced. You can make a button as advanced as you want but it really isn't hard to do. The features that i assume are hardest to others and brings about the so called "advanceness" of it is playing different scenes and adding math features to buttons. The math features i understand because they can get confusing but i mean the scenes? Well, anyway i'll tell you all.
Making a button play a certain scene is just as easy as making the button play a certain frame. All that you add is another part of code before the frame number. Like so...
on (release){
gotoAndPlay("Scene 1", 1);
}
The bold section is what we added. All this tells the program to do is play a scene that is labeled Scene 1 and play frame 1 of that scene. Simple? Well, then why did you not tell me to put that in the simple button section? Anyway that is all you can do with that. You can't tell a button to play a scene inside of a movieclip because movieclips don't have scenes to play. You can though tell a button inside of a movieclip to play a scene on the main timeline. You would use the exact same code as above to do so. That is all for the "Scene" buttons.
Note: you can change the name of your scenes if you want to be more organized. To do so you can go up to Movie Explorer. You can find it under Windows if you don't already have it out.
For buttons useing math that is a bit more advanced and i can understand why. If you don't know what the operations mean then you can be very confused. To make a button do math or add to something you will need to have a dynamic text box with an instance name. To make a dynamic box click the text field and select dynamic text from the scroll down menu on the properties bar. Type nothing in the text box but give it an instance name of "totalMoney" without the quotes.
Now to use a button to add to your money. Make a button say with a plus sign in it. When you are done with that open up the actions panel. To make it so that everytime you release the + button you get 5 dollars you can simple put this code in.
on (release){
totalMoney += 5;
}
When you would test your movie nothing would happen when you push the button because totalMoney has no value yet. To add value to totalMoney go to frame 1 and open the actions panel. Add this code to line 1.
totalMoney = 5
Test your movie again and you should have your money going up by 5's. Now, lets add the minus money option. Make a button like a minus sign. Then open up the actions panel again to add this code to minus your money.
on (release){
totalMoney -= 5;
}
And test your movie. Now you should be able to add and subtract your money value. If you want to all out and make your own calculator make two more buttons. For your first of your two buttons make it a mulitiple sign and add this code to it.
on (release){
totalMoney *= 5;
}
That will times everything by 5. Now for the last one make a dividing sign on your button and add this code to it.
on (release){
totalMoney /= 5;
}
This is how you can make a button link to a website page:
on (release) {
geturl("http://www.awebsite.com (http://www.awebsite.com/)");
}
This will divide everything in the dynamic box by 5. Now that you are done with the buttons test your movie again and see all you can do with making decimals and huge numbers. Hope this tutorial has been useful i will add more things to it when i find them out. I think i already know that i'm missing a few things but i'm tired and i can't think of them right now. Have a great day.
Oh, and don't be afraid to click the rep button... ^_^.