Creating Flash Buttons

by Milan Midovich.

Share
|
Homepage | Submit your article | Contact | TOS
More articles on flash  

You are here: Categories » Computers and technology » Flash

Buttons are one of the three main types of symbols that you use in Flash. The others are movie clips and graphics.

Making a New Button

There are many ways to create a button. One method is to choose Insert, New Symbol from the menu. You are presented with a dialog asking you to name the symbol and to choose whether it is a movie clip, button, or graphic. Choose Button.

The main Flash window now changes to show the button's timeline instead of the movie's main timeline. There are four frames in a button timeline. They are labeled Up, Over, Down, and Hit. They represent the three button states, and the active area of the button.

If you place a graphic, such as a circle, in the first frame and nothing in the other three frames, the Over and Down states of the button will be the same as the Up state. The active area of the button will be the same as well.

On the other hand, you can create a different graphic for each key frame.

When you are finished creating your button, return to the main timeline by clicking the name of the scene, usually Scene 1, where it appears just under the timeline.

Now, open up the library by choosing Window, Library. You should see the button in the library. Drag it to the work area in the main window.

Adding a Script to a Button

To add a script to a button, first select the button. Then bring up the Actions panel. Alternatively, you can right-click the button in Windows, or Control+click the button on the Mac. Select Actions from the menu that appears.

Make sure that the Actions panel is set to Expert mode. You can check this in the pop-up menu that is activated at the upper-right corner of the window.

Here is a typical button script. You can place this in the script window and then test the movie to see whether it works.

on (release) {
   trace("You clicked the button!")
   }

Button scripts use a special syntax that starts with the on keyword. This creates a handler. It is called that simply because it "handles" an event. In this case, the event is release, which is what happens when the user clicks the button and then releases. That is the most common type of button event.

You could also use the alternative event press in place of release. The difference is that the handler will run when the user first clicks the button and will not wait for the user to release the mouse button.

When a handler is activated, the code inside the brackets is executed. In this case, just a trace command is there. It sends a message to the Output window to let you know that the script worked.

Now let's put our knowledge of ActionScript navigation commands and button scripts to work.

Leave a comment or ask a question
Total comments: 0

Flash Disclaimer

  • The e-articles directory is not responsible for any and all copyright infringements by writers and authors. If you suspect the information contained by this page for any copyright infringements, please contact us to investigate the issue
Move Clip Rotation - A property like _x and _y is the movie clip property _rotation. The _rotation property accepts a value in degrees. A circle is divided into 360 degrees. The values used by _rotation range f (more...)
Targeting Flash Movie Clips - The simplest way to target a movie clip is to use its name, followed by a dot, followed by the command you want to send. However, there are plenty of other ways to target a movie clip as we (more...)
Using Mathematical Operators in ActionScript - You want to modify something over time, such as the rotation or position of a movie clip. Use the compound assignment operators to change a variable or property in increments. Or, if increm (more...)
How to build an animated button using Flash - Time: 15 Minutes. Difficulty Level: Intermediate Requirements: Flash 8 Assumed Knowledge: Basic action (more...)
Enhancing Standalone Projector - You want to create an enhanced Standalone Projector with features such as borderless playback, custom titles, no Flash menus, and so on. Use a third-party tool such as SWF Studio or SWFKit to c (more...)
Bouncing Ball Script - Start a new Flash movie. Create a movie clip that has a ball graphic inside it. You can name the instance of the movie clip, myClip, but our code will not depend on the name of the clip. (more...)
ActionScript: Creating Reusable Code - You want to perform a series of actions at various times without duplicating code unnecessarily throughout your movie. Create a function and then call (i.e., invoke) it by name whenever you (more...)
3D Scaling with ActionScript - Although Flash is not capable of real 3D graphics, the kind seen in popular computer games, you can create the illusion of 3D by using scaling. Scaling an object is a great way to give your (more...)
The Dot Syntax - Something else that you will be seeing a lot of as you learn ActionScript is dot syntax. Dot syntax is a way of grouping objects and functions that is used in many object-oriented programming (more...)
Movie Clip Scripts - Movie clip scripts, like button scripts, use handlers. Instead of using the on keyword that button scripts use, we will use the onClipEvent keyword. Here is an example of a movie clip script: (more...)

 
free content
    Copyright © 2006 - 2012 e-articles.info.
The texts, articles and tutorials in the directory are property of their respective owners and authors.