User Guide
272 Chapter 10: Creating Custom Classes with ActionScript 2.0
The following example shows that you can then reference either of the classes directly in the same
script:
var myRos:Rosencrantz = new Rosencrantz();
var myGuil:Guildenstern = new Guildenstern();
The import statement applies only to the current script (frame or object) in which it’s called. If
an imported class is not used in a script, the class is not included in the resulting SWF file’s
bytecode, and the class isn’t available to any SWF files that the FLA file containing the
import
statement might load. For more information, see
import in Flash ActionScript Language Reference.
Compiling and exporting classes
By default, classes used by a SWF file are packaged and exported in the SWF file’s first frame. You
can also specify the frame where your classes are packaged and exported. This is useful, for
example, if a SWF file uses many classes that require a long time to download. If the classes are
exported in the first frame, the user has to wait until all the class code has downloaded before that
frame appears. By specifying a later frame in the Timeline, you could display a short loading
animation in the first few frames of the Timeline while the class code in the later frame
downloads.
To specify the export frame for classes for a Flash document:
1.
With a FLA file open, select File > Publish Settings.
2.
In the Publish Settings dialog box, click the Flash tab.
3.
Click the Settings button next to the ActionScript version pop-up menu to open the
ActionScript Settings dialog box.
4.
In the Export Frame for Classes text box, enter the number of the frame where you want to
export your class code.
If the frame specified does not exist in the Timeline, you will get an error message when you
publish your SWF file.
5.
Click OK to close the ActionScript Settings dialog box, and then click OK to close the Publish
Settings dialog box.
During compilation, Flash sometimes creates files with .aso extensions in the /aso subdirectory of
the default global classpath directory (see “Global and document-level classpaths” on page 268).
The .aso extension stands for ActionScript object (ASO). These files contain the compiled form of
a class file.
The compiler creates ASO files for caching purposes. You might notice that your first compilation
is slower than subsequent compilations. This is because only the AS files that have changed are
recompiled into ASO files. For unchanged AS files, the compiler reads the already-compiled
bytecode directly out of the ASO file instead of recompiling the AS file.
The ASO file format is an intermediate format developed for internal use only. It is not a
documented file format and is not intended to be redistributed.