230
Classes
Working with packages
Packages are directories that contain one or more class files and reside in a designated
classpath directory. For example, the flash.filters package is a directory on your hard disk that
contains several class files for each filter type (such as BevelFilter, BlurFilter,
DropShadowFilter, and so on) in Flash 8.
The
import
statement lets you access classes without specifying their fully qualified names.
For example, if you want to use the BlurFilter class in a script, you must refer to it by its fully
qualified name (flash.filters.BlurFilter) or import it; if you import it, you can refer to it by its
class name (BlurFilter). The following ActionScript code demonstrates the differences
between using the
import
statement and using fully qualified class names.
If you don’t import the BlurFilter class, your code needs to use the fully qualified class name
(package name followed by class name) in order to use the filter:
// without importing
var myBlur:flash.filters.BlurFilter = new flash.filters.BlurFilter(10, 10,
3);
The same code, written with an
import
statement, lets you access the BlurFilter using only
the class name instead of always having to use the fully qualified name. This can save typing
and reduce the chance of making typing mistakes:
// with importing
import flash.filters.BlurFilter;
var myBlur:BlurFilter = new BlurFilter(10, 10, 3);
If you were importing several classes within a package (such as the BlurFilter,
DropShadowFilter, and GlowFilter) you could use one of two methods of importing each
class. The first method of importing multiple classes is to import each class using a separate
import
statement, as seen in the following snippet:
import flash.filters.BlurFilter;
import flash.filters.DropShadowFilter;
import flash.filters.GlowFilter;
Using individual
import
statements for each class within a package can quickly become very
time consuming and prone to typing mistakes. The second method of importing classes
within a package is to use a wildcard import that imports all classes within a certain level of a
package. The following ActionScript shows an example of using a wildcard import:
import flash.filters.*; // imports each class within flash.filters package
NO
TE
To use the
import
statement, you must specify ActionScript 2.0 and Flash Player 6 or
later in the Flash tab of your FLA file’s Publish Settings dialog box.
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...