Creating classes with ActionScript 2

ActionScript 2 is a restructuring of the ActionScript language that provides several new powerful programming features common to other programming languages, like Java. ActionScript 2 encourages program structures that are reusable, scalable, robust, and maintainable. It also cuts development time by providing users with thorough coding assistance and debugging information. ActionScript 2 also conforms to existing standards and is based on the ECMAScript 4 proposal.

The features of ActionScript 2 are outlined below.

Familiar object-oriented programming model The primary feature of ActionScript 2 is a familiar model for creating object-oriented programs. It introduces several new object-oriented concepts and keywords like class, interface, and packages that will be familiar to you if you've every programmed with Java.

The OOP model provided by ActionScript 2 is a "syntactic formalization" of the prototype chaining method used in previous versions of Flash to create objects and establish inheritance. For more information, see ActionScript 2 for ActionScript 1 Programmers.) For an example of creating and using a class see Using classes: a simple example.

Strong data typing ActionScript 2 also provides strong data typing for variables, function parameters and function return types. For example, the following code declares a variable named userName of type String (an built-in ActionScript data type, or class).

var userName:String = "";

Compiler warnings and errors The two previous features describe provide the authoring tool and compiler to provide a wealth of useful compiler warnings and errors that help you track down bugs in your applications faster than was previously possible in Flash.

Note that ActionScript 2 doesn't provide any new significant runtime ActionScript features. The benefits are mainly confined to the development and debugging processes. For more information see Runtime considerations of ActionScript 2. For a list of new ActionScript features in Flash Player 7 see What's New in Matador ActionScript.