Flash Script – Building a Button Component

Share this article


Download the sample files here.

You can use Macromedia Flash UI components to quickly and easily add simple user interface elements to your Flash document.

In this tutorial, we’ll look at how easy it is to use the button component.

1. Open the components panel by clicking ctrl+f7.

2. Drag the Push Button component onto the stage.

3. Select the Push Button component in Frame 1. The component’s parameters are displayed in the Property inspector.

4. To name the component, type "btn1" in the Property inspector Instance Name text box.

5. Type "f1" to name the Click Handler. Later you can write ActionScript to define exactly what the Click Handler should do.

1180_1

6. Select the first key frame from the existing layer, and press f9 to open the actions box.

7. Insert the following action:

function f1(name) 
{
if(name == btn1)
{btn1.setLabel("Button Pressed ")}
}

This action is simple — when you press the button, it calls the function f1().

8. The function has a parameter name which takes the Instance name of the button — in this case, btn1.

9. The If condition checks to see if the event is from btn1. If it is from btn1, it sets the label of button to "Button presed".

This is just a simple example. You can insert any number of events in the If block — experiment and see what you come up with!

Georgina LaidlawGeorgina Laidlaw
View Author

Georgina has more than fifteen years' experience writing and editing for web, print and voice. With a background in marketing and a passion for words, the time Georgina spent with companies like Sausage Software and sitepoint.com cemented her lasting interest in the media, persuasion, and communications culture.

Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week
Loading form