MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual page 330

Actionscript reference guide
Hide thumbs Also See for FLASH MX 2004 - ACTIONSCRIPT:
Table of Contents

Advertisement

Description
Statement; defines a custom class, which lets you instantiate objects that share methods and
properties that you define. For example, if you are developing an invoice-tracking system, you
could create an invoice class that defines all the methods and properties that each invoice should
have. You would then use the
The name of the class must be the same as the name of the external file that contains the class. For
example, if you name a class Student, the file that defines the class must be named Student.as.
The class name must be fully qualified within the file in which it is declared; that is, it must reflect
the directory in which it is stored. For example, to create a class named RequiredClass that is
stored in the myClasses/education/curriculum directory, you must declare the class in the
RequiredClass.as file like this:
class myClasses.education.curriculum.RequiredClass {
}
For this reason, it's good practice to plan your directory structure before you begin creating
classes. Otherwise, if you decide to move class files after you create them, you will have to modify
the class declaration statements to reflect their new location.
You cannot nest class definitions; that is, you cannot define additional classes within a
class definition.
To indicate that objects can add and access dynamic properties at runtime, precede the class
statement with the
keyword. To create subclasses of a class, use the
class, but can implement several interfaces.) You can use
single statement.
class C implements Interface_i, Interface_j
class C extends Class_d implements Interface_i, Interface_j
class C extends Class_d, Class_e
For more information, see
Example
The following example creates a class called Plant. Its constructor takes two parameters.
// Filename Plant.as
class Plant {
// Define property names and types
var leafType:String;
var bloomSeason:String;
// Following line is constructor
// because it has the same name as the class
function Plant (param_leafType:String, param_bloomSeason:String) {
// Assign passed values to properties when new Plant object is created
leafType = param_leafType;
bloomSeason = param_bloomSeason;
}
// Create methods to return property values, because best practice
// recommends against directly referencing a property of a class
function getLeafType():String {return leafType};
function getBloomSeason():String {return bloomSeason};
}
330
Chapter 12: ActionScript Dictionary
new invoice()
keyword. To create classes based on interfaces, use the
dynamic
"Creating and using classes" on page
command to create invoice objects.
keyword. (A class can extend only one
extends
implements
// OK
// not OK
161.
implements
and
in a
extends
// OK

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents