This is an archived tutorial from the kirupa.com legacy collection. It covers software that may no longer be available, but it is kept online because the ideas still hold up.
Whenever you click on something, there is a very good chance that what you clicked on is a button. This is not something specific to just Flash - almost all applications use buttons for doing something. Given how common place they are, lets use this tutorial as a way of familiarizing ourselves with buttons in Flash!
By the end of this tutorial, you will have created a button that looks and functions similar to the following:
[ Hover over and click on the button ]
In the above example, I have a small button made up of some image and text. Play with the button by hovering over it with your mouse and clicking on it. There are two things I want you to notice. First, notice that the look of the button changes as you mouse over and click it. Second, depending on whether you are mousing over or clicking, some text below changes to display what action you just performed.
In this and the following sections, you'll learn how to do everything seen in the above example from actually creating your button to writing the code. Let's get started:

[ is there nothing sweeter than a blank stage? ]
![]()
You cannot copy and paste an
image into Flash from your browser. Instead, you have to
save the image to your hard drive and then insert it by
dragging/dropping from your hard drive and into your
document or by going to File | Import | Import to Stage.
Your perfectly empty stage now contains a lonely image:
![]()
[ your stage now has the image you inserted ]

[ write some text to go along with the image ]

[ select both your image and text ]
With both of these elements selected, hit F8 or go to Modify | Convert to Symbol to launch the Convert to Symbol dialog. In this dialog, for the name, write simpleButton, and under Type, select the Button type:

[ give your new symbol the type Button and name simpleButton ]
Once you have done this hit OK to accept the changes you have made and to close the Convert to Symbol dialog.

[ your selection has been condensed into one element now ]
Looking in your Properties panel paints a much clearer picture.

[ the properties inspector is more clear ]
What you have selected is now a button - as you would have expected after having completed the previous step.

[ you have a very simple button ]
The only visual indicator you have that this is a button is the mouse cursor changing. We want go a bit further, so let's look into that starting in the next section.
In the previous section, you learned how to take some content and make it into a button. As you saw from my example and what you had at the end of the previous section, a button is more than just a container. It needs to provide some feedback beyond the mouse cursor, and it needs to be told what needs to be done.
Let's get started with creating the various button states so that you get more visual feedback when you are interacting with your button:

[ double click or right-click, Edit in Place to edit your button ]

[ the navigation bar shows that you are no longer at the root, Scene 1 ]
Second, look at your timeline. It displays four distinct frames - Normal, Over, Down, and Hit:

[ your timeline when editing a button is different ]
What you are going to do is add content to each of the various frames to indicate when the content will be visible.

[ add new Layers below Layer 1 ]

[ insert a new keyframe in the Over frame ]
The other approach is to right click on each of the empty frames in the Over frame individually and select Insert Keyframe. Either case, the result will be the same.

[ draw a straight line to simulate an underline ]
Because you drew your line in the Over frame in Layer 2, the empty keyframe that once lived there is now a solid keyframe:

[ your empty keyframe is now filled in with your underline ]

[ draw a rectangle large enough to contain your image and text ]
To be able to easily draw the
rectangle behind the underline layer (Layer 2) and the
image/text layer (Layer 1), you may need to lock Layers 1
and 2 first to avoid the "snapping to other things" that
occurs when you are drawing.
Your timeline will
now look as follows with the empty keyframe under Layer 3's
Over frame filled in:

[ your timeline is getting more filled in now ]

[ your Down column will now have keyframes ]

[ change your rectangle's color to a light shade of blue ]
There are several ways in Flash that you can change the color of something. The easiest way is to change the color defined in the Fill property found in the Properties panel when your rectangle is selected:

[ change the color easily from the Properties panel ]
If you test your application now, everything should be good to go. By default, your button looks as follows as defined by the frames in the Normal column:

When you hover over your button, the text is underlined with a pink rectangle appearing as defined by the frames in the Over column:

Finally, when you click on the button, the frames from the Down column are activated, and you see the pink rectangle turn a slight blue:

Ok, great. You now have something that sort of looks and behaviors like a button. It's time to go back to the root of your stage and look at the next step of making a real button. You can go back to the root by clicking on the Scene 1 text found in the navigation bar:

[ go back to the root by clicking on the Scene 1 link ]
Once you are back to the root, let's look at how the button will interact with code in the next section.
In the previous section, you finished the visual side of making a button. You got the normal, over, and down states working. In this page, you will add some code that actually makes your button do more than just look pretty.
To have your button do different things beyond changing its look when you hover over it or click on it, you need to write some code. First, you will need to give your button an instance name so that you can refer to it from your code. Make sure your button is selected, and from the your Properties panel, you'll see a text field at the very top that says "Instance Name":

[ find the Instance Name text field ]
Replace the text with the name myButton:

[ give your button the instance name myButton ]
Once you have given your button an instance name, you can easily refer to it using code. Let's look at the code itself next. All code in Flash is entered primarily via the Actions window. To display the window, select the first frame on your timeline and hit F9 or right click and select Actions from the menu that appears.
Your Actions window will appear:

[ your Actions window will contain your code ]
It is here where you will write some code that will make your button work. What I am going to is provide you the code to do basic handling of mouse over and click events, and then I'll explain in detail how it all works.
Into your Actions window, copy and paste the following code:
function setupEvents() {
// associate events with event handlers
myButton.addEventListener(MouseEvent.CLICK, clickButtonHandler);
myButton.addEventListener(MouseEvent.MOUSE_OVER, hoverButtonHandler);
}
setupEvents();
function clickButtonHandler(e:MouseEvent) {
trace("Clicked Button!");
}
function hoverButtonHandler(e:MouseEvent) {
trace("Hovered Over Button!");
}
Once you have pasted your code, test your application again and press Ctrl + Enter or go to Control | Test Movie. Your application will appear in the Flash Player window. Go ahead and hover over and click on your button. The Output panel will appear, and you will see some text such as "Clicked Button" or "Hovered Over Button" appear:

[ look at the Output panel ]
The output you see is an indication that you have written some code that intercepts your mouse events on your button and does something based on it. Let's look at what the code does...starting with setupEvents:
function setupEvents() {
// associate events with event handlers
myButton.addEventListener(MouseEvent.CLICK, clickButtonHandler);
myButton.addEventListener(MouseEvent.MOUSE_OVER, hoverButtonHandler);
}
setupEvents();
The setupEvents functions gets called first, and it just associates each mouse event with the appropriate function that needs to be called when that event is found. That is handled by the following two lines:
myButton.addEventListener(MouseEvent.CLICK, clickButtonHandler);
myButton.addEventListener(MouseEvent.MOUSE_OVER, hoverButtonHandler);
To take a few steps back, here is what you are trying to accomplish. When you click on the button or when you move your mouse over the button, you want some code to be executed. To determine when you click or when you mouse over something, you need something in the background that periodically checks where your mouse is and whether it is over your button or clicking on the button.
That something in ActionScript is known as a listener. A listener is something you attach, much like a parasite, to a host. The host is the element that you want to intercept and process the events on. When an event you are listening for is overheard, your listener is responsible for calling the appropriate function to handle this event. This function is commonly known as an event handler.
In our code, the host is myButton:
myButton.addEventListener(MouseEvent.CLICK, clickButtonHandler);
myButton.addEventListener(MouseEvent.MOUSE_OVER, hoverButtonHandler);
On the myButton instance, we call the addEventListener function to associate an event with an event handler it needs to call.
In the first line...
myButton.addEventListener(MouseEvent.CLICK, clickButtonHandler);
...we tell our listener to listen for the MouseEvent.CLICK event, and when the click event is heard, call the clickButtonHandler function.
In the second line, we do something very similar:
myButton.addEventListener(MouseEvent.MOUSE_OVER, hoverButtonHandler);
Our listener associates the MouseEvent.MOUSE_OVER event with the hoverButtonHandler that gets called when the mouse over event is overheard.
The only missing piece right now is our event handler. Let's look at our two event handlers next:
function clickButtonHandler(e:MouseEvent) {
trace("Clicked Button!");
}
function hoverButtonHandler(e:MouseEvent) {
trace("Hovered Over Button!");
}
Your event handler is nothing more than a regular function with the exception of one thing - it must have an argument of type that is Event or based on Event. In our code, our argument is of type MouseEvent because both of the listeners are actually listening to something found in the MouseEvent class.
Be careful to note that not all events will be mouse events, so be prepared to change the argument to your event handler to the appropriate event type as needed.
Well, this wraps up or overview of buttons - both the visuals as well as the code needed to make them useful. If you are curious to see how my example looks, feel free to download the source files below:
Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence, ads, and algorithm-driven doodads. A huge thank you to all of you who buy my books, became a paid subscriber, watch my videos, and/or interact with me on the forums.
Your support keeps this site going! 😇

:: Copyright KIRUPA 2026 //--