View Full Version : Everything Buttons [Flash][Actionscript]

09-04-2005, 04: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... ^_^.

09-04-2005, 05:31 PM
*dereps* OMG OPPS lol jp nice tut man u are THE TUT GOD

10-12-2005, 01:20 PM
tell us the code you have written

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

10-12-2005, 01:30 PM
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

10-24-2005, 11:12 AM
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)

10-29-2005, 09:19 PM
You forgot

on(keyPress"a key")

besides that, good job!

11-12-2005, 10:04 PM
W00tness im sooooooo sooooooo happy!!! Thank you!!! I my AS Test it done

11-22-2005, 04:39 AM
herer i tried something with your buttons im just testing this out though not sure if it will work.


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

11-22-2005, 04:50 AM
You don't put stop() in the frame where is the play button.

11-22-2005, 10:18 PM
herer i tried something with your buttons im just testing this out though not sure if it will work.


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

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.

11-25-2005, 07:12 AM
thank u again.

12-04-2005, 06:58 AM
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.

02-18-2006, 10:22 AM
i suck at making buttons!

03-18-2006, 02:38 PM
sorry to bump but the frame with the button on it won't just stay until the click can some one help

03-18-2006, 03:11 PM
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.

bobbly bob9
03-25-2006, 07:02 AM
im making a game and i dont know how to make the instructions button without creating a new scene or messing it up. Also im not sure how to make the game...lol

05-06-2006, 11:26 PM

05-06-2006, 11:27 PM
on (release){ gotoAndPlay(a number); }

on (release){ _root.instancename.gotoAndPlay(a number); }

on (release){ gotoAndPlay("Scene 1", 1); }

on (release){ totalMoney += 5; }

totalMoney = 5

on (release){ totalMoney -= 5; }

on (release){ totalMoney *= 5; }

on (release){ totalMoney /= 5; }

on (release) { geturl("http://www.awebsite.com"); }

05-08-2006, 03:43 PM
nice tut. dont doublepost, noobsarenew2. and thanx for getting my sig out of your's. ask next time.

SoMe GuY
05-26-2006, 12:04 PM
how do i put in the commands and where?

06-18-2006, 05:51 AM
for example i made one little movie with a grenade exploding and it has two layers and its about 60 frames long.When i try to make that into a symbol or movieclip i cant choose convert to symbol.How do you do it so that the grenade movie becomes a movieclip then a button into my other movie?
Sorry i know that this is kinda confusing.

06-18-2006, 01:40 PM
Okay, start off by making a blank movieclip... meaning get the brush tool and clicking once on the stage to create a dot. Then convert that dot to a movieclip and then delete the dot in the edit mode. Get out of edit mode and there will be nothing there. Delete the movieclip off the stage and highlight all the frames you want in the movieclip. Once all your frames are selected right click and hit copy frames. Double click on the empty movieclip in the library to bring up the edit mode and then right click on the empty keyframe and select paste frames. Exit edit menu and you will have your animation in a movieclip.

Now that you have your movieclip you will need to add the button function. Bring up teh edit mode for the movieclip again. Type in the following action, "stop();" on the first frame of the animation. This will prevent the movieclip from playing the animation. Now, the button function can be done two ways:

1. You can make a box around the whole movieclip and convert it to a button. Then turn the alpha down to 0% to make it invisible. Then add these actions to the button:

_root.thenameofyourmovieclipinstance.gotoAndPlay(2 );
2. Drag the movieclip onto the stage and selected it so that it is highlighted. Then bring up the actions panel. Add this code to it:

The code that is used on a button will work on a movieclip. So it is very useful. I hope this helps. Good luck on making whatever you are trying to make. If something is unclear ask another question.

09-19-2006, 03:52 PM
thanks soooo much ive made like 10 videos and finaly i can add a play button

07-06-2007, 01:14 AM
HELP!! i wanted to make a button for an advertisement, like paperclips sig when you request for a new name, you just have to click on that part of the sig.

08-10-2007, 07:01 AM
Thank you for your tutorial. It helped.

08-10-2007, 11:00 AM
i still don't get how to make the buttons do things when you place you arrow over them im not much on actionscriping

10-22-2007, 10:34 PM
god dammit just tell me a simple way to do it.just straight to the point

11-15-2007, 07:12 PM
sorry for the bump, oh and btw, i have made a button, but for the code, do i need a new layer or just add another frame and start animating,im so confused,
i used this code


please, somebody explain

11-16-2007, 11:53 PM
1. Select the button you have made
2. Pull up the actions window
3. Paste the code in the window
4. Exit the actions window
5. Make sure you have a second frame on the timeline
6. Animate as usual, your button will start playing your animation starting from frame 2.

02-10-2008, 08:08 PM
Sorry for the big bump but, what if I have already animated my movie and I want to add a button to play it. I make an empty frame in the beginning and I put the button in the frame. I AS the button with
and when I press ctrl+enter, it just plays the movie like normal. So, whats up? How come my button isn't working?

02-10-2008, 08:49 PM

go to it. read it about halfway down. all your problems will be solved.

Death Angel
03-20-2008, 11:01 AM
Am this didnt help me understand one thing im trying to get to work...how can i make a button display a text if a sertain thing is selected in the ComboBox,lets say i have a few names in a combobox and when i select one of them then click the button i whant a text to be desplayed ,how do i do that?

04-26-2008, 04:46 PM
Nice tut, althought im getting pretty $%#@ed up when i try to make the play button lead somewhere... Good tutorial anyways

04-28-2008, 07:52 PM
How do I make a button play music?

05-05-2008, 07:18 AM
i love how you went into more advanced stuff, like money and plus, minus
soo good :D

06-17-2008, 06:14 PM
i doesnt work =(

06-17-2008, 06:20 PM
nvm XD i try other ways

06-17-2008, 09:35 PM
woot thx!!! ^-^ wit your codes i made a answer the question game

06-19-2008, 03:52 AM
Don't try to triple post, edit your first. This keeps you away from an infraction.

08-12-2008, 06:03 PM
how do i make my buttons move and stuff????????????

08-13-2008, 06:17 AM
You have to put a movieclip in one of those frames.

08-10-2009, 01:08 PM
eh im to stupid i dont get it XD

09-05-2009, 01:53 PM
when I try to make a button lead somewhere else in the animation with this:
on (release){
there is an error that says: "extra charactars found after end of program
on (realease){"

10-17-2009, 02:34 PM
this is difficult

01-29-2010, 10:07 AM
nice guys im new here HI