Specifications

Create a custom class 259
Create a custom class
Although ActionScript includes many classes of objects, such as the
MovieClip class and the Color class, there will be times when you need to
construct your own classes so you can create objects based on a particular
set of properties or methods.
To create a class that defines each of the new objects, you create a
constructor for a custom object class and then create new object instances
based on that new class, as in the following example:
function Product (id:Number, prodName:String, price:Number)
{
this.id = id;
this.prodName = prodName;
this.price = price;
}
To properly define a class in ActionScript 2.0, you must surround all classes
by the
class keyword, and you must declare all variables in the
constructor outside of the constructor.
class Product
{
// variable declarations
var id:Number
var prodName:String
var price:Number
// constructor
function Product (id:Number, prodName:String,
price:Number){
this.id = id;
this.prodName = prodName;
this.price = price;
}
}
NOTE
The following ActionScript is an example only. Do not enter the script in
your lesson FLA file.
NOTE
The following ActionScript is an example only. Do not enter the script in
your lesson FLA file.