MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 277

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

To specify package paths, use dot (
paths are hierarchical; that is, each dot represents a nested directory. For example, suppose you
create a class named ClassName that resides in a
in your classpath. To create an instance of that class, you could specify the fully qualified
class name.
You can also use the fully qualified class name to type your variables, as shown in the
following example:
var myInstance:com.macromedia.docs.learnAs2.ClassName = new
com.macromedia.docs.learnAs2.ClassName();
You can use the
import
abbreviated name rather than its fully qualified name. You can also use the wildcard character
(
) to import all the classes in a package. If you use the wildcard character, you don't need to
*
use the fully qualified class name each time you use the class.
For example, suppose that in a script you imported the above class using the
statement, as shown in the following example:
import com.macromedia.docs.learnAs2.util.UserClass;
Later, in the same script, you could reference that class by its abbreviated name, as shown in
the following example:
var myUser:UserClass = new UserClass();
You can use the wildcard character (
you have a package named
ClassA.as and ClassB.as. In another script, you could import both classes in that package
using the wildcard character, as shown in the following code:
import com.macromedia.utils.*;
The following example shows that you can then reference either of the classes directly in the
same script:
var myA:ClassA = new ClassA();
var myB:ClassB = new ClassB();
The
statement applies only to the current script (frame or object) in which it's called.
import
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
statement might load.
The following exercise is part of
on page 276
which continues the examples
need ClassA and ClassB, you can download the class files from
www.helpexamples.com/flash/learnas/classes/.
) notation to separate package directory names. Package
.
statement to import packages into a script, which lets you use a class's
) to import all the classes in a given package. Suppose
*
com.macromedia.utils
"Example: Using custom class files in Flash"
com/macromedia/docs/learnAs2
that contains two ActionScript class files,
"Example: Writing custom
Example: Using custom class files in Flash
package
import
import
classes". If you
277

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

This manual is also suitable for:

Flash 8

Table of Contents