Using a class file in Flash

To create an instance of an ActionScript class, use the new operator to invoke the class's constructor function. The constructor function always has the same name as the class and returns an instance of the class, which you typically assign to a variable. For example, if you were using the User class from Writing custom class files, you would write the following code to create a new User object:

var firstUser:User = new User();

NOTE

In some cases, you don't need to create an instance of a class to use its properties and methods. For more information on class (static) members, see About class (static) members and Static methods and properties.

Use the dot (.) operator to access the value of a property in an instance. Type the name of the instance on the left side of the dot, and the name of the property on the right side. For example, in the following statement, firstUser is the instance and username is the property:

firstUser.username

You can also use the top-level or built-in classes that make up the ActionScript language in a Flash document. For example, the following code creates a new Array object and then shows its length property:

var myArray:Array = new Array("apples", "oranges", "bananas");
trace(myArray.length); // 3

For more information on using custom classes in Flash, see Example: Using custom class files in Flash. For information on the constructor function, see Writing the constructor function.