![]() ![]() ![]() | |
![]() | |
![]() | |
![]() |
A class's constructor is a special function that is called automatically when you create an instance of a class using the new
operator. The constructor function has the same name as the class that contains it. For example, the Person class you created earlier contained the following constructor function:
// Person class constructor function function Person (myName:String, myAge:Number) { name = myName; age = myAge; }
If no constructor function is explicitly declaredthat is, if you don't create a function whose name matches that of the classthe compiler automatically creates an empty constructor function for you.
A class can contain only one constructor function; overloaded constructor functions are not allowed in ActionScript 2.0.
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |