Understanding the classpath
169
For example, the following code first checks if the object name
someObject
implements the
Movable interface before calling the
moveUp()
method on the object.
if(Movable(someObject) != null) {
someObject.moveUp();
}
Understanding the classpath
In order to use a class or interface that you’ve defined, Flash must be able to locate the external AS
files that contain the class or interface definition. The list of directories in which Flash searches for
class and interface definitions is called the
classpath
.
When you create an ActionScript class file, you need to save the file to one of the directories
specified in the classpath, or a subdirectory therein. (You can modify the classpath to include the
desired directory path; see
“Modifying the classpath” on page 170
.) Otherwise, Flash won’t be
able to
resolve
, or locate, the class or interface specified in the script. Subdirectories that you create
within a classpath directory are called
packages
and let you organize your classes. (For more
information, see
“Using packages” on page 171
.)
Global and document-level classpaths
Flash has two classpath settings: a global classpath and a document-level classpath. The global
classpath applies to external AS and FLA files and is set in the Preferences dialog box (Edit >
Preferences). The document-level classpath applies only to FLA files and is set in the Publish
Settings dialog (File > Publish Settings) for a particular FLA.
By default, the global classpath contains two directory paths: a relative path that points to the
directory that contains the current document, and the Classes directory located in the user
configuration directory installed with Flash. The location of this directory is shown here:
•
Windows 2000 or Windows XP: C:\Documents and Settings\<user>\Local Settings\
Application Data\Macromedia\Flash MX2004\<language>\Configuration\
•
Windows 98: C:\Windows\Application Data\Macromedia\Flash MX 2004\
<language>\Configuration\
•
Macintosh OS X: Hard Drive/Users/Library/Application Support/Macromedia/
Flash MX 2004/<language>/Configuration/
The document-level classpath is empty by default.
How the compiler resolves class references
When Flash attempts to resolve class references in a FLA script, it first searches the document-
level classpath specified for that FLA. If the class is not found in that classpath, or if that classpath
is empty, Flash searches the global classpath. If the class is not found in the global classpath, a
compiler error occurs.
When Flash attempts to resolve class references in an AS script, it searches only the global
classpath directories, since AS files don’t have an associated document class path.
Summary of Contents for FLASH MX 2004 - ACTIONSCRIPT
Page 1: ...ActionScript Reference Guide...
Page 8: ...8 Contents...
Page 12: ......
Page 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Page 54: ...54 Chapter 2 ActionScript Basics...
Page 80: ...80 Chapter 3 Writing and Debugging Scripts...
Page 82: ......
Page 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Page 112: ......
Page 120: ...120 Chapter 6 Using the Built In Classes...
Page 176: ......
Page 192: ...192 Chapter 10 Working with External Data...
Page 202: ...202 Chapter 11 Working with External Media...
Page 204: ......
Page 782: ...782 Chapter 12 ActionScript Dictionary...
Page 793: ...Other keys 793 221 222 Key Key code...
Page 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Page 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Page 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Page 816: ...816 Index...