3.
Select Control > Test Movie to test the Flash document.
For more information on named functions, see
"Writing named functions" on page
207.
Classes contain many user-defined functions. For information on writing functions in class
files, see
"Using functions in Flash" on page
214. Also see the following sections in
Chapter 7,
"Classes":
"Using methods and properties from a class file" on page
245,
"About public,
private, and static methods and properties (members)" on page
247, and
"About class
members" on page
250.
Naming functions
Function names should start with a lowercase letter. Your function names should describe the
value the function returns, if any. For example, if the function returns the title of a song, you
might name it
.
getCurrentSong()
Establish a standard for grouping similar functions (functions that relate to each other based
on functionality), because ActionScript does not permit overloading. In the context of object-
oriented programming (OOP), overloading refers to the ability to make your functions behave
differently depending on what data types are passed into them.
As with variables, you cannot use special characters, and the method name cannot start with a
number. For more information, see
"Naming conventions" on page
732. For information on
naming methods, see
"Naming methods" on page
224.
Using functions in Flash
This section shows you how to use functions in an application. Some of the following code
examples use ActionScript that resides in the FLA file, and other code examples place
functions in a class file for comparison. For more information and examples on using
functions in a class file, see
Chapter 7, "Classes," on page
225. For detailed information and
instruction on how to write functions for a class file, see
"Example: Writing custom classes"
on page
263.
To reduce the amount of work you have to do, as well as the size of your SWF file, try to reuse
blocks of code whenever possible. One way you can reuse code is by calling a function
multiple times instead of creating different code each time. Functions can be generic pieces of
code; you can use the same blocks of code for slightly different purposes in a SWF file.
Reusing code lets you create efficient applications and minimizes the ActionScript code that
you must write, which reduces development time.
214
Functions and Methods
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?