Paradigm | Multi-paradigm: object-oriented (prototype-based), functional, imperative, scripting |
---|---|
Designed by | Gary Grossman |
Developer | Macromedia (now dissolved into Adobe Systems) |
First appeared | 1998 |
Stable release | 3.0 / June 27, 2006 |
Typing discipline | strong, static |
Website | adobe.com/devnet/actionscript/ |
Major implementations | |
Adobe Flash Player, Adobe AIR, Apache Flex, Scaleform GFx | |
Influenced by | |
HyperTalk, JavaScript, Java | |
Influenced | |
Haxe, TypeScript [1] |
Filename extension | .as |
---|---|
Internet media type | application/ecmascript [2] |
ActionScript is an object-oriented programming language originally developed by Macromedia Inc. (later acquired by Adobe). It is influenced by HyperTalk, the scripting language for HyperCard. [3] It is now an implementation of ECMAScript (meaning it is a superset of the syntax and semantics of the language more widely known as JavaScript), though it originally arose as a sibling, both being influenced by HyperTalk. ActionScript code is usually converted to byte-code format by a compiler.
ActionScript is used primarily for the development of websites and software targeting the Adobe Flash platform, originally finding use on web pages in the form of embedded SWF files.
ActionScript 3 is also used with the Adobe AIR system for the development of desktop and mobile applications. The language itself is open-source in that its specification is offered free of charge [4] and both an open-source compiler (as part of Apache Flex) and open-source virtual machine (Tamarin) are available.
ActionScript was also used with Scaleform GFx for the development of three-dimensional video-game user interfaces and heads up displays.
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). [5] 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. [6]
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. [12] 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:
createTextField("greet",0,0,0,100,100);greet.text="Hello, world";
When writing external ActionScript 2.0 class files the above example could be written in a file named Greeter.as as following.
classcom.example.GreeterextendsMovieClip{publicfunctionGreeter(){vartxtHello:TextField=this.createTextField("txtHello",0,0,0,100,100);txtHello.text="Hello, world";}}
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:
vartxtHello:TextField=newTextField();txtHello.text="Hello World";this.addChild(txtHello);
Minimal ActionScript 3.0 programs may be somewhat larger and more complicated due to the increased separation of the programming language and the Flash IDE.
Presume the following file to be Greeter.as:
packagecom.example{importflash.text.TextField;importflash.display.Sprite;publicclassGreeterextendsSprite{publicfunction Greeter(){vartxtHello:TextField=newTextField();txtHello.text="Hello World";addParent(txtHello);}}}
ActionScript 3 can also be used in MXML files when using Apache's Flex framework:
<?xml version="1.0" encoding="utf-8"?><s:Applicationxmlns:fx="http://ns.adobe.com/mxml/2009"xmlns:s="library://ns.adobe.com/flex/mx/polysylabi"xmlns:mx="library://ns.adobe.com/flex/mx"layout="vertical"creationComplete="initApp()"><fx:Script><![CDATA[publicfunction initApp():void{// Prints our "Hello, world!" message into titletitle.text="Hello, World!";}]]></fx:Script><s:Labelid="title"fontSize="54"fontStyle="bold"/></s:Application>
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 types [13]
ActionScript 3 some complex data types [13]
The basic syntax is:
varvariableName:VariableType=newVariableType(param1,param2,...,paramN);
So in order to make an empty Object:
varmyObject:Object=newObject();
Or, in an informal way:
varmyObject={};
Some types are automatically put in place:
varmyString:String="Hello Wikipedia!";// This would automatically set the variable as a string.varmyNumber:Number=5;// This would do the same for a number.varmyObject:Object={param1:"Hi!",param2:76};// This creates an object with two variables.// param1 is a string with the data of "Hi!",// and param2 is a number with the data of 76.// This is the syntax for automatically creating an Array.varmyArray:Array=[5,"Hello!",{a:5,b:7}];// It creates an Array with 3 variables.// The first (0) is a number with the value of 5,// the second (1) is a string with the value of "Hello!",// and the third (2) is an object with { a: 5, b: 7 }.
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. [14]
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:
varitem1:String="ABC";varitem2:Boolean=true;varitem3:Number=12;varitem4:Array=["a","b","c"];varitem5:Object={name:"Actionscript",version:"3.0"};varitem6:XML=<node><child/></node>;// Note that the primitive XML is not quoted
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.
varitem1:XML=newXML("<node><child /></node>");varitem2:XML=item1;item2.firstChild.attributes.value=13;// item1 now equals item2 since item2 simply points to what item1 points to.// Both are now:// <node><child value="13" /></node>
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.
varitem1:XML=newXML("<node><child /></node>");deleteitem1;// If no other reference to item1 is present anywhere else in the application,// it will be removed on the garbage collector's next pass
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). [15] [16] [17]
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.[ citation needed ]
JavaScript, often abbreviated as JS, is a programming language and core technology of the Web, alongside HTML and CSS. 99% of websites use JavaScript on the client side for webpage behavior.
ECMAScript is a standard for scripting languages, including JavaScript, JScript, and ActionScript. It is best known as a JavaScript standard intended to ensure the interoperability of web pages across different web browsers. It is standardized by Ecma International in the document ECMA-262.
Adobe ColdFusion is a commercial rapid web-application development computing platform created by J. J. Allaire in 1995. ColdFusion was originally designed to make it easier to connect simple HTML pages to a database. By version 2 (1996) it had become a full platform that included an IDE in addition to a full scripting language.
Apache Flex, formerly Adobe Flex, is a software development kit (SDK) for the development and deployment of cross-platform rich web applications based on the Adobe Flash platform. Initially developed by Macromedia and then acquired by Adobe Systems, Adobe donated Flex to the Apache Software Foundation in 2011 and it was promoted to a top-level project in December 2012.
JSON is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays. It is a commonly used data format with diverse uses in electronic data interchange, including that of web applications with servers.
Adobe Flash Player is a discontinued computer program for viewing multimedia content, executing rich Internet applications, and streaming audio and video content created on the Adobe Flash platform. It can run from a web browser as a browser plug-in or independently on supported devices. Originally created by FutureWave under the name FutureSplash Player, it was renamed to Macromedia Flash Player after Macromedia acquired FutureWave in 1996. After Adobe acquired Macromedia in 2005, it was developed and distributed by Adobe as Adobe Flash Player. It is currently developed and distributed by Zhongcheng for users in China, and by Harman International for enterprise users outside of China, in collaboration with Adobe.
The syntax of JavaScript is the set of rules that define a correctly structured JavaScript program.
Adobe Media Server (AMS) is a proprietary data and media server from Adobe Systems. This server works with the Flash Player and HTML5 runtime to create media driven, multiuser RIAs. The server uses ActionScript 1, an ECMAScript based scripting language, for server-side logic. Prior to version 2, it was known as Flash Communication Server. Prior to version 5, it was known as Flash Media Server. In February 2019, Adobe Systems Incorporated granted Veriskope Inc rights to further develop, resell, and extend distribution of the software product.
Haxe is a high-level cross-platform programming language and compiler that can produce applications and source code for many different computing platforms from one code-base. It is free and open-source software, released under an MIT License. The compiler, written in OCaml, is released under the GNU General Public License (GPL) version 2.
Action Message Format (AMF) is a binary format used to serialize object graphs such as ActionScript objects and XML, or send messages between an Adobe Flash client and a remote service, usually a Flash Media Server or third party alternatives. The Actionscript 3 language provides classes for encoding and decoding from the AMF format.
Language Integrated Query is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages, originally released as a major part of .NET Framework 3.5 in 2007.
The syntax and semantics of PHP, a programming language, form a set of rules that define how a PHP program can be written and interpreted.
Adobe Flash Builder is an integrated development environment (IDE) built on the Eclipse platform that speeds development of rich Internet applications (RIAs) and cross-platform desktop applications, particularly for the Adobe AIR platform. Adobe Flash Builder 4 is available in two editions: Standard and Premium.
WSO2 Mashup Server, an open-source mashup platform that used to host JavaScript-based mashups, is now deprecated and no longer in use. It was based on Apache Axis2 and other open-source projects, and allowed JavaScript to consume, compose and emit web services, feeds, scraped web pages, email, and instant messages. The source code was freely available under the open-source Apache License. It provided a runtime platform for developing and deploying mashups and could be downloaded and deployed locally or within an organization.
Google Closure Tools is a set of tools to help developers build rich web applications with JavaScript. It was developed by Google for use in their web applications such as Gmail, Google Docs and Google Maps. As of 2023, the project had over 230K LOCs not counting the embedded Mozilla Rhino compiler.
Rexx is a programming language that can be interpreted or compiled. It was developed at IBM by Mike Cowlishaw. It is a structured, high-level programming language designed for ease of learning and reading. Proprietary and open source Rexx interpreters exist for a wide range of computing platforms; compilers exist for IBM mainframe computers.
Swift is a high-level general-purpose, multi-paradigm, compiled programming language created by Chris Lattner in 2010 for Apple Inc. and maintained by the open-source community. Swift compiles to machine code and uses an LLVM-based compiler. Swift was first released in June 2014 and the Swift toolchain has shipped in Xcode since version 6, released in 2014.
Nim is a general-purpose, multi-paradigm, statically typed, compiled high-level system programming language, designed and developed by a team around Andreas Rumpf. Nim is designed to be "efficient, expressive, and elegant", supporting metaprogramming, functional, message passing, procedural, and object-oriented programming styles by providing several features such as compile time code generation, algebraic data types, a foreign function interface (FFI) with C, C++, Objective-C, and JavaScript, and supporting compiling to those same languages as intermediate representations.
ECMAScript is a JavaScript standard developed by Ecma International. Since 2015, major versions have been published every June.