You can use the fully qualified class name to type your variables, as well:
var dataInstance:com.network.Data = new Data();
You can use the
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 macr/util/users:
// In the file macr/util/users/UserClass.as
class macr.util.users.UserClass { ... }
Suppose that in another script, you imported that class as follows using the
import macr.util.users.UserClass;
Later in the same script you could reference that class by its abbreviated name:
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
and bar.as. In another script, you could import both classes in that package using the wildcard
character, as shown below.
import macr.util.*;
In the same script, you can then reference either the foo or bar class directly.
var myFoo:foo = new foo();
var myBar:bar = new bar();
The
statement applies only to the current script (frame or object) in which it's called. If
import
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 call. For more information, see
Implicit get/set methods
Object-oriented programming practice discourages direct access to properties within a class.
Classes typically define "get" methods that provide read access and "set" methods that provide
write access to a given property. For example, imagine a class that contains a property called
:
userName
var userName:String;
Instead of allowing instances of the class to directly access this property (
, for example), the class might have two methods,
"Jody"
would be implemented as follows:
function getUserName:String() {
return userName;
}
function setUserName(name:String): {
userName = name;
}
172
Chapter 9: Creating Classes with ActionScript 2.0
statement to import packages into a script, which lets you use a class's
import
macr.util
that contains two ActionScript class files, foo.as
on page
400.
import
getUserName
statement:
import
import
obj.userName =
and
, that
setUserName
Need help?
Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?