# class

#### Availability

Flash Player 6.

#### Usage

    class ClassName {}
    class ClassName extends ClassName {}
    class ClassName implements InterfaceName [, InterFaceName... ] {}

Note: To use this keyword, you must specify ActionScript 2 and Flash Player 6 or Flash Player 7 in the Flash tab of your FLA file's Publish Settings dialog box. This keyword is supported only when used in external script files, not in scripts written in the Actions panel.

#### Description

Keyword; defines a custom object 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 `new` operator to create invoice objects.You cannot nest class definitions; that is, you cannot define additional classes within a class definition.

To create classes based on interfaces, use the `implements` keyword. To create subclasses of a class, use the `extends` keyword. (A class can extend only one class, but can implement several interfaces.) You can use `implements` and `extends` in a single statement.

    class c implements interface_i, interface_j    //OK
    class c extends class_d implements interface_i, interface_j    //OK
    class c extends class_d, class_e    //not OK

#### 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};
    }

In an external script file or in the Actions Panel, use the `new` operator to create an object of type Plant.

    var pineTree:Plant = new Plant("Evergreen","N/A");
    // Confirm parameters were passed correctly
    trace(pineTree.getLeafType());
    trace(pineTree.getBloomSeason());

#### See also

`dynamic`, `extends`, `implements`, `interface`, `new`