Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Classes > About object-oriented programming and Flash > About packages > 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.
|
NOTE |
|
To use the |
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
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 that package by their class names instead of their fully qualified names. If you wanted to use the class name on another frame script, however, you would need to 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 using import statements, it's also important to note that classes are imported only for the level specified. For example, if you imported all classes in the mx.transitions package, only those 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 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. |
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000769.html