EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 205

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
About functions and methods 205
To add a top-level function call to your code, just add a single line of code in the Script pane
of the Actions panel. For example, type the following:
trace("my message");
When you test the SWF file with this single line of code, the top-level trace() function is
called, and text appears in the Output panel.
Remember: when you want to assign a method to a property, you omit the parentheses after
the method name because youre passing a reference to the function:
my_mc.myMethod = aFunction;
However, when you want to invoke a method in your code, you need to include the
parentheses following the method name:
my_mc.myMethod();
You can also define functions in numerous other ways. For more information on each kind of
function, see the following sections:
About built-in and top-level functions” on page 205
“Writing named functions” on page 207
“Writing anonymous and callback functions” on page 208
About function literals” on page 211
“Targeting and calling user-defined functions” on page 213
About constructor functions” on page 211
For information on writing and using functions and methods, see the following related
sections. For information on using functions, see “Using functions in Flash” on page 214. For
information on using methods, see “Understanding methods” on page 222.
About built-in and top-level functions
As discussed in About functions and methods” on page 201, a function is a block of
ActionScript code that can be reused anywhere in a SWF file. If you pass values as parameters
to a function, the function operates on those values. A function can also return values.
NOTE
For more information on top-level functions, see “About built-in and top-level functions”
on page 205.
NOTE
For information on writing code using Script Assist, see “Using Script Assist to write
ActionScript” on page 328, “Creating a startDrag/stopDrag event using Script Assist”
on page 331 and the ActionScript:Use Script Assist Mode tutorial (which begins with
“Open the starter document” on page 213).

Table of Contents

Related product manuals