Everything Buttons [Flash][Actionscript]

Started by: Paperclip | Replies: 44 | Views: 21,804

Paperclip

Posts: 840
Joined: Nov 2004
Rep: 500

View Profile
Sep 4, 2005 9:43 PM #445
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");
}

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... ^_^.
lilcrash

Posts: 0
Joined: Nov 2025
Sep 4, 2005 10:31 PM #448
YAH PAPERCLIP
*dereps* OMG OPPS lol jp nice tut man u are THE TUT GOD
Jevon
2

Posts: 203
Joined: Aug 2005
Rep: 106

View Profile
Oct 12, 2005 6:20 PM #1347
tell us the code you have written

and great tut!!! i actually understand the _.root one now!! cheers man!
Mitch

Posts: 0
Joined: Nov 2025
Oct 12, 2005 6:30 PM #1348
it dont matter any more i figured it out thaks for helpin any way lol i had a frame with an action script that said stop and i also didnt put in the nexts scene i wanted to play
Maximus

Posts: 0
Joined: Nov 2025
Oct 24, 2005 4:12 PM #1692
Every time I try to make a Button and i run the movie. a error is poping up. i dont know what i am doing wrong. but maybe you can make a tut that is zooming inn on the basic button. (play and replay)
briceman92

Posts: 0
Joined: Nov 2025
Oct 30, 2005 2:19 AM #1742
You forgot

on(keyPress"a key")

besides that, good job!
Tru_Power

Posts: 0
Joined: Nov 2025
Nov 13, 2005 4:04 AM #2027
W00tness im sooooooo sooooooo happy!!! Thank you!!! I my AS Test it done
MortalDays

Posts: 0
Joined: Nov 2025
Nov 22, 2005 10:39 AM #2350
herer i tried something with your buttons im just testing this out though not sure if it will work.

Image

dam how come this is happening i will put this in help aswell!
pain

Posts: 0
Joined: Nov 2025
Nov 22, 2005 10:50 AM #2351
You don't put stop() in the frame where is the play button.
McBob

Posts: 0
Joined: Nov 2025
Nov 23, 2005 4:18 AM #2365
Quote from b!ake
herer i tried something with your buttons im just testing this out though not sure if it will work.

Image

dam how come this is happening i will put this in help aswell!

LOL.

You don't save it as a gif, you save it as an swf.
Gifs can't have sound or buttons, they're just images.
MortalDays

Posts: 0
Joined: Nov 2025
Nov 25, 2005 1:12 PM #2422
thank u again.
froggeh.
2

Posts: 27
Joined: Nov 2005
Rep: 10

View Profile
Dec 4, 2005 12:58 PM #2590
can u go into more details with the functions adn stuff, so 1st, insert an object ot be the button.
or whatever, this tut should be for complete noobs too. ewait ill check if sum1's done it already.
Shadow_Theif^-^

Posts: 0
Joined: Nov 2025
Feb 18, 2006 4:22 PM #4845
i suck at making buttons!
heckyes
2

Posts: 3
Joined: Dec 2005
Rep: 10

View Profile
Mar 18, 2006 8:38 PM #5995
sorry to bump but the frame with the button on it won't just stay until the click can some one help
RhinoCharge!
2

Posts: 15
Joined: Mar 2006
Rep: 10

View Profile
Mar 18, 2006 9:11 PM #5996
Quote from Shadow_Theif^-^
i suck at making buttons!
I suck at making babies, but you don't see me spamming.

The tutorial is awesome, really great work Paperclip.