ActionScript is an ECMAScript-based programming language used for scripting Adobe Flash movies and applications. ActionScript 1.0 was first released with Flash 5, its first completely programmable version. Flash 6 added several built-in functions and allowed better programmatic control of animated elements. ActionScript 2.0 was introduced in Flash 7, which was strongly typed and allowed class-based programming features, such as inheritance, interfaces, and strict data typing. Flash 8 further extended ActionScript 2 by adding new class libraries with APIs for controlling bitmap data at runtime and file upload. The ActionScript Virtual Machine (AVM1), which is built into Flash Player, executes ActionScript. With the new virtual machine, ActionScript Virtual Machine (AVM2), Flash 9 (which comes with ActionScript 3) shows a significant performance improvement.
Older versions of ActionScript (ActionScript 1.0 and 2.0) offered the power and flexibility required for creating rich Web applications. ActionScript 3 now opens up a wide range of possibilities for Web-based applications. It further advances the language by providing excellent performance and ease of development to facilitate highly complex Web applications and large data sets. ActionScript 3 helps you achieve high performance and productivity with content and applications that target Flash Player.
ActionScript 3 is compliant with the ECMAScript Language Specification, Third Edition. It also contains functionalities based on ECMAScript Edition 4, such as classes, packages, and namespaces; optional static typing; generators and iterators; and destructuring assignments. As the project requirements for rich, high-performing Web applications increased, the demand for a major breakthrough in the ActionScript Engine increased as well. ActionScript 3 introduces a new highly optimized ActionScript Virtual Machine (AVM2) that dramatically exceeds the performance possible with AVM1. This is what makes the ActionScript 3 code execute nearly 10 times faster than the legacy ActionScript code. AVM2, the new scripting language engine for ActionScript 3.0 introduced with Flash Player 9, was designed to deliver the performance and features to support the needs of rich Internet application developers. Flash Player will continue to support the older AVM1 for backwards compatibility with existing and legacy content.
Products that incorporate ActionScript 3
Numerous products, including YouTube, Flickr, SWiSH, and ScreenTime, generate content and applications targeted at the Flash Player Runtime. 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 applications for Flash Player Runtime. 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.
Starting with the general features of ActionScript 3, I'll talk about the goals, language features, and Flash Player API features. I will also discuss the new and unnoticed features of ActionScript 3. On November 7, 2006, in the WEB 2.0 conference, San Francisco, Adobe Systems declared that it has contributed the source code for ActionScript Virtual Machine to the Mozilla Foundation. Mozilla will host a new open source project called Tamarin, to accelerate the development of this standards-based approach for creating rich and engaging Web applications.
ActionScript 3 has two kinds of features: language features and Flash Player API features. The language features are basically built on ActionScript 2, but some improvements in performance and functionality include:
- Many runtime exceptions to improve common error handling and debugging abilities. These runtime exceptions display the stack trace, so that you can easily find the root cause of the error. Earlier ActionScript versions ate up the error silently to avoid error message dialogs from popping up in Flash. This was difficult during development stages because developers were not made aware of the possible errors to make a good product.
- The type details are stored during runtime for checking and to safeguard the system, making ActionScript 3 strongly typed. This also helps to reduce memory usage, since the type information represents variables in native machine representation.
- ActionScript 3 follows the ECMAScript, Fourth Edition specification completely, simplifying XML parsing.
ActionScript 3's Flash Player API features include:
- The DOM3 event model gives you a standard way of generating and handling event messages, which helps in better communication and interaction between objects.
- The new
Loaderclass provides a single mechanism for loading Shockwave Flash files and image assets and provides a way to access detailed information about loaded content. TheURLLoaderclass provides a separate mechanism for loading text and binary data in data-driven applications. - The
Socketclass provides a means to read and write binary data to server sockets in any format. - ActionScript 3.0 contains a flash.text package for all text-related APIs.
Below are other new capabilities.
This method lets you create items directly on the display list from binary data. For example, in my e-mail client, if an e-mail downloaded from a Pop3 server contains an attachment, I check the attachment's mime-type. If it is a type that the player supports, then I can read the attachment's binary source into a ByteArray and display the attachment inside Flash Player. This means that my e-mail client can display PNG, JPEG, GIF, and SWF attachments.
This method analyzes all the sound that played and returns a ByteArray containing 512 normalized values (-1 to 1) that you can use to visually display the sound waveform (256 values for the left channel and 256 values for the right channel). You can use these values to create Audio Equalizers for Media Players as well as visual experiments that react to the sound that played.
This method returns a ByteArray containing the hexadecimal color value of each pixel in a bitmap's specified rectangular region. You can use this method in conjunction with the new ZLib compression method, ByteArray.compress(), to compress and send a bitmap over the wire to a server, converting it into a downloadable file.
You can now stop the player from continuing to load external media. In the past, if you loaded an image into the player, you couldn't stop the process until it completed. Now you can.
Following is a list of this new version's benefits:
- The language supports type safety and makes code maintenance easier.
- The language is relatively simple and makes coding easier compared to other languages.
- Developers can write responsive and efficient code with high performance.
- The language has both backward and forward compatibility to ActionScript 2 and ECMAScript for XML (E4X), respectively.
On November 7, 2006, Adobe Systems declared that it has contributed the code for ActionScript Virtual Machine to the Mozilla Foundation. With this, Mozilla has hosted a new open source project called Tamarin. Adobe and Mozilla hope to thereby accelerate the adoption of a standard language for creating engaging Web applications.
The goal of the Tamarin project is to implement a high-performance, open source implementation of the ECMAScript, Fourth Edition (ES4) language specification. Mozilla will use the Tamarin Virtual Machine within SpiderMonkey, the core JavaScript engine embedded in Firefox and other Mozilla-based products. Adobe will continue to use the code as part of the ActionScript Virtual Machine within Adobe Flash Player.
The Tamarin Virtual Machine currently implements the ECMAScript, Third Edition language standard, on which JavaScript, Adobe ActionScript, and Microsoft Jscript, as well as some new language features proposed in ES4, are based. By working on an open source implementation of ES4 with the community, Adobe and Mozilla hope to accelerate the adoption of a standard language for creating engaging Web applications. The Tamarin project aims to accelerate your ability to create and deliver richer, more interactive experiences that work across multiple platforms.
Tamarin will support the forthcoming ECMAScript Edition 4 (or "JavaScript 2") language and will be integrated into SpiderMonkey as part of the Mozilla 2 project, to be released in 2008.
Mozilla's open source project team is just getting started on Tamarin, but some of its technical goals include:
- Integrating the Tamarin VM and garbage collector within SpiderMonkey
- Using the SpiderMonkey compiler to generate code for Tamarin
- Porting the just-in-time compiler to new hardware platforms
- Completing the self-hosting ECMAScript 4 compiler
A simple example using ActionScript 3
This ActionScript example displays a greeting message "Hello <Username>". The user can enter his or her name in the text area provided. When he or she presses Enter, the greeting message is displayed.
Listing 1. Example code
package {
public class Greeter {
/**
* Defines the names that should receive a proper greeting.
*/
public static var validNames:Array = ["Sammy", "Frank", "Dean"];
/**
* Builds a greeting string using the given name
*/
public static function sayHello (userName:String = ""):String {
var greeting:String = "Hello World";
if (userName == ""){
greeting = "Hello, please type your name and then press the enter key";
}
else if(validName(userName)){
greeting = "Hello, " + userName + ".";
}
else {
greeting = "Sorry, " + userName + "Your name is not present in the list.";
}
return greeting;
}
/**
* Check whether a name is in the validNames list
*/
public static function validName(inputName:String = ""):Boolean {
if validNames.indexOf(inputName) > -1 {
return true;
}
else {
return false;
}
}
}
}
|
Figure 1 shows the initial window of Listing 1. It displays the initial greeting, "Hello, please type your name and then press the enter key" and waits for the user to enter something in the text box labeled User Name.
Figure 1. Greeting example in ActionScript 3
When the user enters "Frank" in the User Name field, the script looks for the name in the pre-defined validNames array. Since "Frank" is present in the validNames array, the greeting "Hello Frank" is displayed in the greeting space, as Figure 2 shows.
Figure 2. User enters name
If the user enters a name not present in the validNames array -- for example, User Name = "Anitha" -- then the message, "Sorry, Anitha, your name is not present in the list," will appear.
Below, I've provided excellent study resources related to ActionScript programming. You can also find a link to the discussion forum, where developers who are working on ActionScript will give you an immediate response to any queries. While beyond the scope of this article, there are many other exciting changes to the new ActionScript Virtual Machine, and the new Flash Player, in general. If you haven't done so, download the newest version of the Flash Player and enjoy its many benefits.
Learn
-
"ActionScript Programming" gives complete details about ActionScript Programming along with Flash APIs.
-
If interested in joining the Tamarin Project, visit Mozilla Foundation for details and sign up for the mailing list.
-
Visit the ECMAScript Fourth Edition Specification directory for detailed information.
-
Find all packages for the ActionScript 3.0 Language Reference.
Get products and technologies
-
Download Flash Player 9.
-
Download Flex 2 Builder for ActionScript 3.0 programming and MXML programming.
Discuss
-
Post any questions to the ActionScript 3 Forum and get a speedy response.
-
Check out developerWorks
blogs and get involved in the developerWorks community.

Anitha Ramaswamy is a software engineer working with the WebSphere Business Integration Adapters team in IBM India Software Labs, Bangalore. Her area of expertise includes Java™ and Java 2 Enterprise Edition (J2EE™) technologies. She has worked with the OS/2® Presentation Manager for three years. She has also worked on the open source Tuscany Project and the RFIDIC 1.0 installer development project for the EPCIS team in India Software Labs. She holds a bachelor's degree in electronics and communication from Vishwesvaraya Technological University, Bangalore. You can reach Anitha at aramaswa@in.ibm.com.
Comments (Undergoing maintenance)





