Buttons in flash
5,178 ViewsFlash Tutorials March 20th, 2007
Well in this tutorial I will be teaching you how to make buttons in flash.
First step, open flash, any dimensions and any frame rate. Now we want to make the movie stop on the frame that you have your button in, so select the frame that you want your button in on the timeline and open up the actions panel (F9) and add this code:
-
stop();
Ok, so now that the movie stops, we need our button. So select the rectangle tool at the side

and draw a rectangle on the stage, then select the text tool and write some text over the rectangle relevent to what you want your button to do, for my example I will write play over mine.
Next select the rectangle and the text over it and go to Modify > Convert to symbol... or press F8 it will come up with a box like the following...

now change the fields so it looks something like the following...

1 - Name: It doesn't really matter but if you go back to a file it helps you know what everything is.
2 - Type: Important, for a button you want it to have a type of button.
3 - Registration: Doesn't really matter for buttons.
Ok, so we have our button but it doesn't do anything yet. On the UI there is a little panel at the bottom called "properties", I want you to open it. Now with your button selected, change the instance name to button, like the picture below:

1 - Instance name: Change this to button.
Now the code to make the button work. Usually I would make you put this in the button but because of AS3 coming out I am going to do it like this:
-
button.onRelease = function() {
-
gotoAndPlay(x);
-
};
This means that when the object with the instance name of button is pressed it calls a function which takes you to the frame specified in the () tags. The example above will give you a sytax error, this is because you need to change the x to the number equal to the frame that you want the button to take you to; If I wanted the button to take me to frame four, I would change the code to:
-
button.onRelease = function() {
-
gotoAndPlay(4);
-
};
Buttons in flash can do other things aswell, for example if you wanted a button to link back to a website, you would use this code:
-
button.onRelease = function() {
-
getURL("http://www.tutorialcode.com");
-
};
or if you wanted a button you email to a certain email address:
-
button.onRelease = function() {
-
getURL("mailto:example@website.com");
-
};
So the basic code for the frame is:
-
stop();
-
-
button.onRelease = function() {
-
gotoAndPlay(2);
-
};
(that will take you to frame 2).
Thankyou for reading,
mortisimus
P.S. If you have any problems or anything, just comment.

(4 votes, average: 4.5 out of 5)










March 20th, 2007 at 3:11 pm
Good tutorial! Nice first post.
March 21st, 2007 at 2:21 am
Yay, someone liked it!
March 28th, 2007 at 7:11 pm
I try to keep _btn on the end of my button names, _mc on movie clips and _txt on text fields. Flash gives you nifty code hints this way. Try it out.
April 2nd, 2007 at 2:50 pm
No it doesn't.
April 6th, 2008 at 10:00 pm
Very Cool thanks!
May 14th, 2008 at 2:28 pm
I did all this, and I tried to follow other tutorials and the same thing happens. When I click the button, it does nothing. I tried getURL, gotoAndPlay, tried to put the AS in the button (by right-clicking on it and selecting actions) and wrote the code without the "button_name" part. Nothing worked.. but other scripts like stop(); work...
Until now I only had problems with the buttons that require mouse input..
May 14th, 2008 at 2:44 pm
Hmmm...
err... i just tried it again, doing exactly the same things i did... and it worked..
xD
Anyway, this tutorial is good, and explains the very basics of AS with buttons.
Nice post!