Adobe Flash

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.

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

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.

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

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.

Press Enter or Return, and type the following:

screen_mc._visible = true;

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;


by BrainBellupdated