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, it’s 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.
NO
TE
You write the class declaration that reflects the package directory in the following
section,
“Example: Writing custom classes” on page 263
.
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...