Creating A Simple Button With Sound in Flash 8
Creating A Simple Button With Sound in Flash 8
(beginner )
In order to add interactivity to our flash movies we need to create a special type of symbol that will allow the user to tell
the movie to perform some action such as play, next, stop sound etc. By defining a symbol as a button symbol we let
Flash know that this shape will behave as a button (ie something that is clickable). Flash's buttons can be defined to have
a different appearance for each state (up, down, and hover) and we can easily add sound to give more feedback to the user
that something happened in response to their clicking the button. .
A button can be any shape and colour you wish it to be buttons can even be invisible (by defining a hit state only). For the
purposes of this tutorial we are going to create a simple rounded rectangle shape for
our button.
Choose the rectangle tool. Then, in the options section of the toolbox click on the
rounded corner option. This will open the set corner radius dialog box. I entered a
value of 12 but you can experiment with different values to see which results in the
Tip: you can also change the corner radius of a rounded rectangle on the fly
by clicking the up or down arrow buttons while drawing out the shape.
Set the colour of your fill and stroke - in the example button a fill of
blue and no stroke was chosen.
To draw out the shape simply click on the stage and drag out a shape of size you
desire. When you release the mouse button the final shape with the fill and stroke
colours you chose will be displayed.
In most cases buttons will contain text or symbols to let the user know what will
happen when they click on them. First we need to set some attributes for our text,
from the property inspector set the text type to static, choose a font, font-color, font
size. Because this text is not going to be animated I have left the anti-aliasing option
set to Anti-alias for readability. Then simply click on the stage and start typing.
Use the selection tool (black arrow) to drag a marquee around both the text and button or
select the button and shift+click to select the text as well. Then open the alignment panel
by choosing Windows > Align or Ctrl + K (Win) Cmd + K (Mac).
So far we have created a great button shape but at this point it just
looks like a button it actually isn't a button yet. Using the selection
tool (black arrow) draw a marquee around the button shape to select
it or click the button shape and shift click the text to select both objects. Then choose
Modify > Convert to Symbol or F8. This will process will convert it from some a shape
and text that looks like a button to an actual button
symbol.
The up state is how the button appears by default when the user isn't interacting with the
button. The over state is what shows when the user holds his mouse over the button and
the down states is what shows for that brief period when the button is actually clicked on.
Finally the hit state is not a state that is visible to the user but simply defines the shape and space that is clickable by the
user.
Place your cursor in the frame under the Over label and add a keyframe by either choosing Insert >
Timeline > Keyframe or right-clicking and choosing Keyframe from the context menu or F6. This
will place a copy of the existing button shape and text on the stage for the over state. So the user will
see the button react to the mouse over event select the rounded rectangle shape and choose a different fill colour.
Place your cursor in the frame under the Down label and add a keyframe by either choosing Insert >
Timeline > Keyframe or right-clicking and choosing Keyframe from the context menu or F6. This
will place a copy of the existing button shape and text on the stage for the down state. So the user will
see the button react to the mouse over event select the rounded rectangle shape and choose a different fill colour.
Place your cursor in the frame under the Hit label and add a keyframe by either choosing Insert > Timeline > Keyframe or
right-clicking and choosing Keyframe from the context menu or F6. This will place a copy of the existing button shape
and text on the stage for the hit state. All you really need for this state is a shape of the buttons size to let flash know how
big an area should be clickable so leaving this state identical to the down state is just fine.
Test how your button reacts to mouse movement by choosing Control > Test Movie or Ctrl + Enter (Win) or Cmd +
Return (mac)
First we need to import a sound to our library. A great source for event sounds is www.flashkit.com. Flash can use many
types of sound files including .mp3s . wavs.
In the layers palette click the insert layer button. Rename the new layer sounds by
double-clicking within the layer text.
Place your cursor under the Down label in the sound layer and add a keyframe by either choosing
Insert > Timeline > Keyframe or right-clicking and choosing Keyframe from the context menu or F6.
Click inside the keyframe on the sound layer to select it then drag the sound icon
from library and drop it on to the stage. There will be no visible difference to the stage but a blue
wave form will appear within the down keyframe extending beyond it.
Click in the down state keyframe on the sound layer again and on the property inspector make sure
that the sync option is set to event. An event sound will play for its full length regardless if there is
room on the timeline for it or not.
Test how your button reacts to mouse movement by choosing Control > Test Movie or Ctrl + Enter (Win) or Cmd +
Return (mac)
Adding actionscript commands to buttons will be covered in a future tutorial.