Flash Script – Building a Button Component


type = 'application/x-shockwave-flash'
data = 'http://sitepointstatic.com/flash/button.swf'
width = '400'
height = '400'
bgcolor = 'black'
>

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!

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

No Reader comments

Comments on this post are closed.