Writing the constructor

Constructors are methods that have a unique purpose: to set properties and perform other tasks when a new instance of a component is instantiated. You can recognize a constructor because it has the same name as the component class itself. For example, the following code shows the ScrollBar component's constructor:

function ScrollBar() {
}

In this case, when a new ScrollBar component is instantiated, the ScrollBar() constructor is called.

Generally, component constructors should be empty so that the object can be customized with its properties interface. In addition, setting properties in constructors can sometimes lead to overwriting default values, depending on the ordering of initialization calls.

A class can contain only one constructor function; overloaded constructor functions are not allowed in ActionScript 2.0.