• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 20. ActionScript: Write Scripts > Write a function for a button

Write a function for a button

A command in ActionScript is called a function. A function is a script that you can write once and use repeatedly in a document to perform a certain task. You’re going to write a function that makes the screen_mc movie clip appear (visible = true) when the user releases the mouse button.

1.
In the Script pane of the Actions panel, click after the last line of code, press Enter (Windows) or Return (Macintosh) twice, and type // function to show animation

2.
Press Enter or Return and click Insert Target Path, along the top of the Actions panel. Select onButton_btn from the hierarchical tree, and click OK.

3.
In the Script pane, type a period (.) and double-click onRelease from the list of code hints that appears.

4.
In the Script pane, press the Spacebar and type the following:

= function(){

The line of code that you just completed should appear as follows:

this.onButton_btn.onRelease = function(){

You already know how to select objects in the Insert Target Path dialog box; you’ll now enter the instance names directly into the Script pane.

5.
Press Enter or Return, and type the following:

screen_mc._visible = true;

6.
Press Enter or Return and type }; to specify the end of the statement.

The function should appear as follows:

// function to show animation
this.onButton_btn.onRelease = function(){
  screen_mc._visible = true;
};


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint