EasyManua.ls Logo

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

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...
Example: Writing custom classes 267
6. Save the ClassA.as ActionScript document.
7. Select File > New and then select ActionScript File, and then click OK.
8. Select File > Save As, name the new file ClassB.as, and save it in the same directory as
ClassA.as created in an earlier step.
9. Type the following code into the Script window:
class com.macromedia.utils.ClassB {
}
The previous code creates a new class named ClassB in the com.macromedia.utils
package.
10. Save your changes to both the ClassA.as and ClassB.as class files.
The class files you use in a FLA file import into a SWF file when you compile it. The code
you write in a class file should have a certain methodology and ordering, which are discussed
in the following sections.
If you are creating multiple custom classes, use packages to organize your class files. A package
is a directory that contains one or more class files and resides in a designated classpath
directory. A class name must be fully qualified within the file in which it is declared—that is,
it must reflect the directory (package) in which it is stored. For more information on
classpaths, see About setting and modifying the classpath” on page 240.
For example, a class named
com.macromedia.docs.YourClass is stored in the com/
macromedia/docs
directory. The class declaration in the YourClass.as file looks like this:
class com.macromedia.docs.YourClass {
// your class
}
For this reason, its good practice to plan your package structure before you begin creating
classes. Otherwise, if you decide to move class files after you create them, you will have to
modify the class declaration statements to reflect their new location.
To package your class files:
1. Decide on the package name you’d like to use.
Package names should be intuitive and easily identifiable by fellow developers. Remember
that the package name also matches a specific directory structure. For example, any classes
in the
com.macromedia.utils package needs to be placed in a com/macromedia/utils
folder on your hard drive.
NOTE
You write the class declaration that reflects the package directory in the following
section, “Example: Writing custom classes” on page 263.

Table of Contents

Related product manuals