Understanding ActionScript > About scripting in ActionScript

About scripting in ActionScript

You can start writing simple scripts without knowing much about ActionScript. All you need is a goal; then it's just a matter of picking the right actions. The best way to learn how simple ActionScript can be is to create a script. The following steps attach a script to a button that changes the visibility of a movie clip.

To change the visibility of a movie clip:

1 Choose Window > Common Libraries > Buttons, and then choose Window > Common Libraries > Movie Clips. Place a button and a movie clip on the Stage.
2 Select the movie clip instance on the Stage, and choose Window > Panels > Instance Properties.
3 In the Name field, enter testMC.
4 Select the button on the Stage, and choose Window > Actions to open the Actions panel.
5 In the Object Actions panel, click the Actions category to open it.
6 Double-click the setProperty action to add it to the Actions list.
7 From the Property pop-up menu, choose _visible (Visibility).
8 For the Target parameter, enter testMC.
9 For the Value parameter, enter 0.
The code should look like this:
on (release) {
    setProperty ("testMC", _visible, false);
}
10 Choose Control > Test Movie and click the button to see the movie clip disappear.

ActionScript is an object-oriented scripting language. This means that actions control objects when a particular event occurs. In this script, the event is the release of the mouse, the object is the movie clip instance testMC, and the action is setProperty. When the user clicks the onscreen button, a release event triggers a script that sets the _visible property of the object MC to false and causes the object to become invisible.

You can use the Actions panel to guide you through setting up simple scripts. To use the full power of ActionScript, it is important to understand how the language works: the concepts, elements, and rules that the language uses to organize information and create interactive movies.