ActionScript was initially designed for controlling simple two-dimensional vector animations made in Adobe Flash (formerly Macromedia Flash). Initially focused on animation, early versions of Flash content offered few interactivity features, thus had very limited scripting ability. Later versions added functionality allowing for the creation of web-based games and rich web applications with streaming media (such as video and audio). Today, ActionScript is suitable for desktop and mobile development through Adobe AIR; it is used in some database applications and in basic robotics as in Make Controller Kit.
Flash MX 2004 introduced ActionScript 2.0, a scripting language more suited to the development of Flash applications. Saving time is often possible by scripting something rather than animating it, which usually also enables a higher level of flexibility when editing.
Since the arrival of the Flash Player 9 alpha (in 2006), a newer version of ActionScript has been released, ActionScript 3.0. This version of the language is intended to be compiled and run on a version of the Tamarin virtual machine, formerly ActionScript Virtual Machine 2, that was also fully rewritten (dubbed AVM2).3 Because of this, code written in ActionScript 3.0 is generally targeted for Flash Player 9 and higher, and will not work in prior versions. At the same time, ActionScript 3.0 executes up to 10 times faster than legacy ActionScript code due to the just-in-time compiler enhancements.4
Flash libraries can be used with the XML abilities of the browser to render rich content in the browser. This technology is known as Asynchronous Flash and XML, much like AJAX. Adobe offers its Flex product line to meet the demand for rich web applications built on the Flash runtime, with behaviors and programming done in ActionScript. ActionScript 3.0 forms the foundation of the Flex 2 application programming interface (API).
ActionScript started as an object-oriented programming language for Macromedia's Flash authoring tool, later developed by Adobe Systems as Adobe Flash. The first three versions of the Flash authoring tool provided limited interactivity features. Early Flash developers could attach a simple command, called an "action", to a button or a frame. The set of actions was basic navigation controls, with commands such as "play", "stop", "getURL", and "gotoAndPlay".
With the release of Flash 4 in 1999, this simple set of actions became a small scripting language. New capabilities introduced for Flash 4 included variables, expressions, operators, if statements, and loops. Although referred to internally as "ActionScript", the Flash 4 user manual and marketing documents continued to use the term "actions" to describe this set of commands.
With the release of Flash 5 in September 2000, the "actions" from Flash 4 were enhanced once more and named "ActionScript" for the first time.10 This was the first version of ActionScript with influences from JavaScript and the ECMA-262 (Third Edition) standard, supporting the said standard's object model and many of its core data types. Local variables may be declared with the var statement, and user-defined functions with parameter passing and return values can also be created. Notably, ActionScript could now also be typed with a text editor rather than being assembled by choosing actions from drop-down lists and dialog box controls. With the next release of its authoring tool, Flash MX, and its corresponding player, Flash Player 6, the language remained essentially unchanged; there were only minor changes, such as the addition of the switch statement and the "strict equality" (===) operator, which brought it closer to being ECMA-262-compliant. Two important features of ActionScript that distinguish it from later versions are its loose type system and its reliance on prototype-based inheritance. Loose typing refers to the ability of a variable to hold any type of data. This allows for rapid script development and is particularly well-suited for small-scale scripting projects. Prototype-based inheritance is the ActionScript 1.0 mechanism for code reuse and object-oriented programming. Instead of a class keyword that defines common characteristics of a class, ActionScript 1.0 uses a special object that serves as a "prototype" for a class of objects. All common characteristics of a class are defined in the class's prototype object and every instance of that class contains a link to that prototype object.
The next major revision of the language, ActionScript 2.0, was introduced in September 2003 with the release of Flash MX 2004 and its corresponding player, Flash Player 7. In response to user demand for a language better equipped for larger and more complex applications, ActionScript 2.0 featured compile-time type checking and class-based syntax, such as the keywords class and extends. While this allowed for a more structured object-oriented programming approach, the code would still be compiled to ActionScript 1.0 bytecode, allowing it to be used on the preceding Flash Player 6 as well. In other words, the class-based inheritance syntax was a layer on top of the existing prototype-based system. With ActionScript 2.0, developers could constrain variables to a specific type by adding a type annotation so that type mismatch errors could be found at compile-time. ActionScript 2.0 also introduced class-based inheritance syntax so that developers could create classes and interfaces, much as they would in class-based languages such as Java and C++. This version conformed partially to the ECMAScript Fourth Edition draft specification.
In June 2006, ActionScript 3.0 debuted with Adobe Flex 2.0 and its corresponding player, Flash Player 9. ActionScript 3.0 was a fundamental restructuring of the language, so much so that it uses an entirely different virtual machine. Flash Player 9 contains two virtual machines, AVM1 for code written in ActionScript 1.0 and 2.0, and AVM2 for content written in ActionScript 3.0. ActionScript 3.0 added limited support for hardware acceleration (DirectX, OpenGL).
The update to the language introduced several new features:
Adobe AIR supports ActionScript, in addition to some extended contents, such as the Stage3D engine Adobe has developed. The number of APIs (Application programming interfaces) available to ActionScript 3.0 has also risen dramatically.
ActionScript code is free form and thus may be created with whichever amount or style of whitespace that the author desires. The basic syntax is derived from ECMAScript.
The following code, which works in any compliant player, creates a text field at depth 0, at position (0, 0) on the screen (measured in pixels), that is 100 pixels wide and high. Then the text parameter is set to the "Hello, world" string, and it is automatically displayed in the player:
When writing external ActionScript 2.0 class files the above example could be written in a file named Greeter.as as following.
ActionScript 3.0 has a similar syntax to ActionScript 2.0, but a different set of APIs for creating objects. Compare the script below to the previous ActionScript 2.0 version:
Minimal ActionScript 3.0 programs may be somewhat larger and more complicated due to the increased separation of the programming language and the Flash integrated development environment (IDE).
Presume the following file to be Greeter.as:
See also: Sprite (computer graphics)
ActionScript 3 can also be used in MXML files when using Apache's Flex framework:
ActionScript primarily consists of "fundamental" or "simple" data types that are used to create other data types. These data types are very similar to Java data types. Since ActionScript 3 was a complete rewrite of ActionScript 2, the data types and their inheritances have changed.
ActionScript 2 top level data types
ActionScript 2 complex data types
There are additional "complex" data types. These are more processor and memory intensive and consist of many "simple" data types. For AS2, some of these data types are:
ActionScript 3 primitive (prime) data types11
ActionScript 3 some complex data types12
The basic syntax is:
So in order to make an empty Object:
Or, in an informal way:
Some types are automatically put in place:
Unlike some object-oriented languages, ActionScript makes no distinction between primitive types and reference types. In ActionScript, all variables are reference types. However, objects that belong to the primitive data types, which includes Boolean, Number, int, uint, and String, are immutable.13
So if a variable of a supposedly primitive type, e.g. an integer is passed to a function, altering that variable inside the function will not alter the original variable, as a new int Object is created when inside the function. If a variable of another (not primitive) datatype, e.g. XML is passed to a function, altering that variable inside the function will alter the original variable as well, as no new XML Object is created.
Some data types can be assigned values with literals:
A reference in ActionScript is a pointer to an instance of a class. A reference stores the memory address of an object – operations against references will follow the value of the reference to the memory address of the object and carry out the operation on that object. All objects in ActionScript are accessed through references instead of being accessed directly.
Only references to an object may be removed by using the "delete" keyword. Removal of actual objects and data is done by the Flash Player garbage collector which checks for any existing references in the Flash memory space. If none are found (no other reference is made to the orphaned object), it is removed from memory. For this reason, memory management in ActionScript requires careful application development planning.
Like most bytecode file formats, Flash SWF files can be decompiled into their source code and assets (similarly to how Microsoft .NET files can be decompiled). Some decompilers are capable of nearly full reconstruction of the original source file, down to the actual code that was used during creation (although results vary on a case-by-case basis).141516
In opposition to the decompilers, ActionScript obfuscators have been introduced, which transform code into a form that breaks decompiler output while preserving the functionality and structure of the program. Higher-quality obfuscators implement lexical transformations such as identifier renaming, control flow transformation, and data abstraction transformation which collectively make it harder for decompilers to generate output likely to be useful to a human. Less robust obfuscators insert traps for decompilers. Such obfuscators either cause the decompiler software to crash unexpectedly or to generate unintelligible source code.
"Apple's lost decade, HyperCard, and what might NOT have been if Apple then was like Apple is today". ZDNet. April 17, 2011. Archived from the original on April 21, 2011. Retrieved December 4, 2014. https://web.archive.org/web/20110421072519/http://www.zdnet.com/blog/government/apples-lost-decade-hypercard-and-what-might-not-have-been-if-apple-then-was-like-apple-is-today/10185 ↩
"ActionScript 3 Language Specification". Archived from the original on March 27, 2017. Retrieved November 12, 2016. https://web.archive.org/web/20170327122455/http://help.adobe.com/livedocs/specs/actionscript/3/wwhelp/wwhimpl/js/html/wwhelp.htm ↩
Brimelow, Lee (August 18, 2008). "Six reasons to use ActionScript 3.0". Adobe Systems Incorporated. Retrieved June 18, 2010. https://www.adobe.com/devnet/actionscript/articles/six_reasons_as3.html ↩
Grossman, Gary; Huang, Emmy (June 27, 2006). "ActionScript 3.0 overview". Adobe Systems Incorporated. Retrieved June 18, 2010. https://www.adobe.com/devnet/actionscript/articles/actionscript3_overview.html ↩
"Standard ECMA-262". Ecma-international.org. Retrieved April 22, 2013. http://www.ecma-international.org/publications/standards/Ecma-262.htm ↩
Waldemar Horwat, ed. (June 30, 2003). "ECMAScript 4 Netscape Proposal". Netscape. Archived from the original on July 11, 2007. Retrieved April 11, 2019. https://web.archive.org/web/20070711065258/http://www.mozilla.org/js/language/es4.html ↩
"Flash Player | Adobe Flash Player 11 | Overview". Adobe.com. April 9, 2013. Retrieved April 22, 2013. https://www.adobe.com/products/flashplayer ↩
"Adobe Labs – Adobe Flash Player 10.1". Labs.adobe.com. Archived from the original on January 5, 2010. Retrieved December 17, 2009. http://labs.adobe.com/technologies/flashplayer10/ ↩
"Flash Player 11 and AIR 3 Release Notes for Adobe Labs" (PDF). Archived from the original (PDF) on July 14, 2011. https://web.archive.org/web/20110714222550/http://download.macromedia.com/pub/labs/flashplatformruntimes/shared/flashplayer11_air3_b1_releasenotes_071311.pdf ↩
"Flash Player 11, AIR 3 Release Notes". helpx.adobe.com. Retrieved October 7, 2016. https://helpx.adobe.com/x-productkb/multi/release-notes-flash-player-11.html ↩
"Data type descriptions + Flash CS3 Documentation". Archived from the original on November 2, 2007. Retrieved July 13, 2007. https://web.archive.org/web/20071102191956/http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000047.html ↩
"Flex 3 – Function parameters". Livedocs.adobe.com. Archived from the original on February 12, 2009. Retrieved December 17, 2009. https://web.archive.org/web/20090212103954/http://livedocs.adobe.com/flex/3/html/03_Language_and_Syntax_19.html ↩
"Third party review of another decompiler". Flashmagazine.com. October 21, 2007. Archived from the original on June 20, 2017. Retrieved April 22, 2013. https://web.archive.org/web/20170620134350/http://www.flashmagazine.com/reviews/detail/review_trillix_flash_decompiler_3/ ↩
"Customer comments on one Flash decompiler". Topshareware.com. Retrieved April 22, 2013. http://www.topshareware.com/reviews/10386-1/flash-decompiler.htm ↩
Customer comments on another Flash product Archived August 18, 2006, at the Wayback Machine http://www.macupdate.com/reviews.php?id=11541 ↩