27 June 2006
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.
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:
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.
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. All of these features are discussed in comprehensive detail in the ActionScript 3.0 Language Reference, available in beta version on Adobe Labs.
Following is a high-level summary of the developer benefits and usage of some of the new features.
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.
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.
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.
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:
myButton.addEventListener("click", 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:
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.
ActionScript3.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 anmx_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.
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
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:
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.
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.
This ActionScript 3.0 overview outlines only a few of the exciting APIs and language features you'll discover as you learn more about ActionScript3.0. Programming ActionScript 3.0 on LiveDocs (or as PDF) is a good place to start for information on how to implement programming concepts in ActionScript, and the ActionScript 3.0 Language Reference will be the definitive source for complete information about the core language and the Flash Player API. Also, if you're already familiar with ActionScript 1.0 or 2.0, check out Tips for Learning ActionScript 3.0.
The Flash Player team is thrilled to be able to deliver a preview of the language, its new capabilities, and improved performance to the community through Adobe Labs. You will be able to explore ActionScript3.0 to see where we are taking the language through Flex Builder 2, the Flex framework, Flex Data Services 2, and Flash Player 9. We hope you are as excited as we are about the future of the platform, and look forward to the feedback you will provide us through Adobe Labs.