Showcase and discover digital art at yex

Follow Design Stacks

Subscribe to our free newsletter to get all our latest tutorials and articles delivered directly to your inbox!

ActionScript 3.0 Overview

ActionScript Article

ActionScript 3.0 is a powerful, object-oriented programming language that signifies an important step in the evolution of the capabilities of the Flash Player runtime. The motivation driving ActionScript 3.0 is to create a language ideally suited for rapidly building rich Internet applications, which have become an essential part of the web experience.

Earlier versions of ActionScript offered the power and flexibility required for creating truly engaging online experiences. ActionScript 3.0 now further advances the language, providing superb performance and ease of development to facilitate highly complex applications, large datasets, and object-oriented, reusable code bases. With ActionScript 3.0, developers can achieve excellent productivity and performance with content and applications that target Flash Player.

ActionScript 3.0 is based on ECMAScript, the international standardized programming language for scripting. ActionScript 3.0 is compliant with the ECMAScript Language Specification, Third Edition (ECMA-262). It also contains functionality based on ongoing work on ECMAScript Edition 4, occurring within the ECMA standards body.

ActionScript is executed by the ActionScript Virtual Machine (AVM) built into the Flash Player. AVM1, the virtual machine used to execute legacy ActionScript code, powers Flash Player today and makes possible a wide range of interactive media and rich Internet applications.

However, developers have started to push AVM1 to its limits; their project requirements now demand a major breakthrough. ActionScript 3.0 introduces a new highly optimized ActionScript Virtual Machine, AVM2, which dramatically exceeds the performance possible with AVM1. As a result, ActionScript 3.0 code executes up to 10 times faster than legacy ActionScript code.

The new AVM2 virtual machine is available in Flash Player 9, and will be the primary virtual machine for ActionScript execution going forward. The older AVM1 will continue to be supported by Flash Player for backwards compatibility with existing and legacy content.

There are numerous products that generate content and applications targeted at the Flash Player runtime. Often these products incorporate support for ActionScript to add interactivity and behavior to their output. In the Adobe product family, professional designers and developers might use ActionScript within several tools and servers—such as Flash, Flex, and Flash Media Server—to create content and applications for Flash Player. The Flex product family, including the new Eclipse-based Flex Builder 2 IDE, will be the first product line to access the new capabilities of ActionScript 3.0.

Goals of ActionScript 3.0

We wanted ActionScript 3.0 to deliver an improved, consistent programming model; compliance with industry standards; and performance an order of magnitude greater than what we delivered in the past. Although ActionScript 3.0 represents a new programming model for the runtime, it is one that will be familiar to developers with a basic knowledge of object-oriented programming.

ActionScript 3.0 is designed to address the following goals:

  • Safety: The language supports type safety so developers can write unambiguous, easily maintainable code.
  • Simplicity: The language is intuitive enough for developers to be able to read and write programs without constantly consulting a reference manual.
  • Performance: The language enables developers to write complex programs that perform efficiently and responsively.
  • Compatibility: The language provides a short backward and forward compatibility path and a significant overlap with industry standards. ActionScript 3.0 is a dialect of ECMAScript which formalizes the features of ActionScript 2.0, adds the capabilities of ECMAScript for XML (E4X), and unifies the language into a coherent whole.

Features of ActionScript 3.0

ActionScript 3.0 consists of two parts: the core language and the Flash Player API. The core language defines the basic building blocks of the programming language, such as statements, expressions, conditions, loops, and types. The Flash Player API is made up of classes that represent and provide access to Flash Player–specific functionality

ActionScript 3.0 contains a host of powerful new features that can greatly speed the development process. Regular expression support enables a variety of powerful operations on text. ECMAScript for XML (E4X) transforms XML into a native data type, dramatically simplifying XML processing. The new Display List API makes working with visual objects far more straightforward and consistent. The standardized DOM event model cements the way those objects talk and respond to each other at runtime. These are only a few of the many new capabilities of ActionScript 3.0.

Language features

ActionScript 3.0 brings the core language aspects of ActionScript 2.0 into compliance with the ECMAScript standard and introduces some areas of new or enhanced functionality.

Following is a high-level summary of the developer benefits and usage of some of the new features.

Runtime exceptions

In ActionScript 2.0, many runtime errors would fail in a graceful but silent fashion. This ensured that Flash Player would not display some inexplicable dialog box, which JavaScript did in early web browsers. On the other hand, this lack of error reporting made it more challenging to debug ActionScript programs.

ActionScript 3.0 introduces a variety of runtime exceptions for common error conditions, improving the debugging experience and enabling applications that handle errors robustly. Runtime errors can provide stack traces annotated with source file and line number information, helping to pinpoint errors quickly.

Runtime types

In ActionScript 2.0, type annotations were primarily an aid for developers; at runtime, all values were dynamically typed.

In ActionScript 3.0, type information is preserved at runtime and utilized for a number of purposes. Flash Player performs runtime type checking, improving the system’s type safety. Type information is also used to represent variables in native machine representations, improving performance and reducing memory usage.

Sealed classes

ActionScript 3.0 introduces the concept of a sealed class. A sealed class possesses only the fixed set of properties and methods that were defined at compile-time; additional properties and methods cannot be added. This makes stricter compile-time checking possible, resulting in more robust programs. It also improves memory usage by not requiring an internal hash table for each object instance. Dynamic classes are also possible using the dynamic keyword.

Method closures

Event handling is simplified in ActionScript 3.0 thanks to method closures, which provide built-in event delegation. In ActionScript 2.0, a closure would not remember what object instance it was extracted from, leading to unexpected behavior when the closure was invoked. The mx.utils.Delegate class was a popular workaround; to use it, you would write code as follows:

Delegate.create(this, someMethod));

Delegate.create(this, someMethod)

This class is no longer needed because in ActionScript 3.0, a method closure will be generated when someMethod is referenced. The method closure will automatically remember its original object instance. Now, one can simply write:

myButton.addEventListener("click", someMethod);           

ECMAScript for XML (E4X)

ActionScript 3.0 features a full implementation of ECMAScript for XML (E4X), recently standardized as ECMA-357. E4X offers a natural, fluent set of language constructs for manipulating XML. Unlike traditional XML parsing APIs, E4X makes XML feel like a native data type of the language. E4X streamlines the development of applications that manipulate XML by drastically reducing the amount of code needed.

Regular expressions

ActionScript 3.0 includes native support for regular expressions so you can quickly search for and manipulate strings. ActionScript 3.0 implements the regular expressions defined in the ECMAScript Language Specification (ECMA-262).


Namespaces are an innovative new mechanism for controlling visibility of declarations. Similar to the traditional access specifiers used to control visibility of declarations (public, private, protected), namespaces are essentially custom access specifiers, which can have names of your choosing. The Flex framework, for example, uses an mx_internal namespace for its internal data. Namespaces are outfitted with a Universal Resource Identifier (URI) to avoid collisions, and are also used to represent XML namespaces when working with E4X.

New primitive types

ActionScript 2.0 had a single numeric type, Number, a double-precision floating point number. One welcome addition to ActionScript 3.0 is the new int type—a 32-bit signed integer that lets ActionScript code take advantage of the fast integer math capabilities of the CPU. The int type is great for loop counters and almost anywhere a decimal point isn’t needed. Another new type is uint, an unsigned 32-bit integer type similar to int.

Flash Player API features

The Flash Player API is a set of classes and functions that expose the capabilities of Flash Player to the ActionScript language. This functionality is the bridge between the ActionScript core language and the rest of the platform. It is the source of much of the power available to Flash applications and is a very important complement to the core language. Although there isn’t space here to cover the APIs in detail, here is a short list of some of the new and interesting functionality available to developers:

DOM3 event model

The event model provides a standard way of generating and handling event messages so that objects within applications can interact and communicate, maintaining state and responding to change. Patterned after the W3C DOM3 Events specification, this model provides a clearer and more efficient mechanism than the event systems available in previous versions of ActionScript. The Flex application framework uses the same event model as the Flash Player API, so the event system is unified across the platform from top to bottom.

Display List API

The Display List API consists of a revamped set of classes for working with the visual primitives in Flash.

The new Sprite class is a lightweight building block, similar to MovieClip but more appropriate as a base class for UI components. The new Shape class represents raw vector shapes. These classes can be instantiated naturally with the new operator and can be dynamically re-parented at any time.

There is no longer any need to assign depth numbers to display list objects. Depth management is now automatic and built into Flash Player. New methods are provided for specifying and managing the z-order of objects.