Importing classes
65
Importing classes
To reference a class in another script, you must prefix the class name with the class’s package path.
The combination of a class’s name and its package path is the class’s
fully qualified class name
. If a
class resides in a top-level classpath directory—not in a subdirectory in the classpath directory—
then its fully qualified class name is its class name.
To specify package paths, use dot (.) notation to separate package directory names. Package paths
are hierarchical, where each dot represents a nested directory. For example, suppose you create a
class named Data that resides in a com/xyzzycorporation/ package in your classpath. To create an
instance of that class, you could specify the fully qualified class name, as shown in the following
example:
var dataInstance = new com.xyzzycorporation.Data();
You can also use the fully qualified class name to type your variables, as shown in the following
example:
var dataInstance:com.xyzzycorporation.Data = new Data();
You can use the
import
statement to import packages into a script, which lets you use a class’s
abbreviated name rather than its fully qualified name. You can also use the wildcard character (*)
to import all the classes in a package.
For example, suppose you created a class named UserClass that’s included in the package directory
path com/xyzzycorporation/util/users:
// In the file com/xyzzycorporation/util/users/UserClass.as
class com.xyzzycorporation.util.users.UserClass { ... }
Suppose that in another script, you imported that class using the
import
statement, as shown in
the following example:
import com.xyzzycorporation.util.users.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 (*) to import all the classes in a given package. For example,
suppose you have a package named
com.xyzzycorporation.util
that contains two
ActionScript class files, Rosencrantz.as and Guildenstern.as. In another script, you could import
both classes in that package using the wildcard character, as shown in the following code:
import com.xyzzycorporation.util.*;
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();
Summary of Contents for FLEX
Page 1: ...Flex ActionScript Language Reference ...
Page 8: ......
Page 66: ...66 Chapter 2 Creating Custom Classes with ActionScript 2 0 ...
Page 76: ......
Page 133: ...break 133 See also for for in do while while switch case continue throw try catch finally ...
Page 135: ...case 135 See also break default strict equality switch ...
Page 146: ...146 Chapter 5 ActionScript Core Language Elements See also break continue while ...
Page 808: ...808 Chapter 7 ActionScript for Flash ...
Page 810: ...810 Appendix A Deprecated Flash 4 operators ...
Page 815: ...Other keys 815 Num Lock 144 186 187 _ 189 191 192 219 220 221 222 Key Key code ...
Page 816: ...816 Appendix B Keyboard Keys and Key Code Values ...
Page 822: ...822 Index ...