Working with filter 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. When class files are organized this way, you must access the classes in a specific way. You either import the class, or reference it using a fully qualified name.

NOTE

 

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.

The import statement lets you access classes without specifying their fully qualified names. For example, to use a BlurFilter 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) in your code instead. 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 the class name instead of continually referencing it using the fully qualified name. This can save typing and reduces the chance of making typing mistakes:

// with importing 
import flash.filters.BlurFilter; 
var myBlur:BlurFilter = new BlurFilter(10, 10, 3);

To import several classes within a package (such as the BlurFilter, DropShadowFilter, and GlowFilter) you can use one of two ways to import each class. The first way to import multiple classes is to import each class by using a separate import statement, as seen in the following snippet:

import flash.filters.BlurFilter;
import flash.filters.DropShadowFilter;
import flash.filters.GlowFilter;

If you use individual import statements for each class within a package, it becomes time consuming to write and prone to typing mistakes. You can avoid importing individual class files by using a wildcard import, which 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

The import statement applies only to the current script (frame or object) in which it's called. For example, suppose on Frame 1 of a Flash document you import all the classes in the macr.util package. On that frame, you can reference classes in the package by using their class names instead of their fully qualified name. To use the class name on another frame script, reference classes in that package by their fully qualified names or add an import statement to the other frame that imports the classes in that package.

When you use import statements, remember that classes are only imported for the level that you specify. For example, if you import all classes in the mx.transitions package, only the classes within the /transitions/ directory are imported, not all classes within subdirectories (such as the classes in the mx.transitions.easing package).

TIP

 

If you import a class but don't use it in your script, the class isn't exported as part of the SWF file. This means that you can import large packages without being concerned about the size of the SWF file; the bytecode associated with a class is included in a SWF file only if that class is actually used.

For an example of using ActionScript to apply filters, you can find a sample source file, Filters.fla, in the Samples folder on your hard disk.


Version 8

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00001507.html