ActionScript

Source: Wikipedia, the free encyclopedia.

ActionScript
Developer
Macromedia (now dissolved into Adobe Systems)
First appeared1998
Stable release
3.0 / June 27, 2006 (2006-06-27)
static
Websiteadobe.com/devnet/actionscript/
Major implementations
Adobe Flash Player, Adobe AIR, Apache Flex, Scaleform GFx
Influenced by
HyperTalk, JavaScript, Java
Influenced
Haxe, TypeScript[1]
ActionScript
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

heads up displays
.

Overview

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

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).

History

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

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.

Timeline by player version

Timeline by ActionScript version

2000–2004: ActionScript "1.0"

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.

instance
of that class contains a link to that prototype object.

2003–2006: ActionScript 2.0

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,

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
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.

2006–2020: ActionScript 3.0

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:

Flash Lite

  • Flash Lite
    1.0
    : Flash Lite is the Flash technology specifically developed for mobile phones and consumer electronics devices. Supports Flash 4 ActionScript.
  • Flash Lite 1.1: Flash 4 ActionScript support and additional device APIs added.
  • Flash Lite 2.0 and 2.1: Added support for Flash 7 ActionScript 2.0 and some additional fscommand2 API.
  • Flash Lite 3: Added support for Flash 8 ActionScript 2.0 and also
    FLV
    video playback.
  • Flash Lite 4: Added support for Flash 10 ActionScript 3.0 as a browser plugin and also hardware graphics acceleration.

AIR

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.

Syntax

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.

ActionScript 2.0

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.

class com.example.Greeter extends MovieClip
{
    public function Greeter()
    {
        var txtHello: TextField = this.createTextField("txtHello", 0, 0, 0, 100, 100);
        txtHello.text = "Hello, world";
    }
}

ActionScript 3.0

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:

var txtHello: TextField = new TextField();
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:

package com.example
{
    import flash.text.TextField;
    import flash.display.Sprite;

    public class Greeter extends Sprite
    {
        public function Greeter()
        {
            var txtHello: TextField = new TextField();
            txtHello.text = "Hello World";
            addParent(txtHello);
        }
    }
}

ActionScript 2 can also be used in MXML files when using Apache's Flex framework:

<?xml version="2.0" encoding="utf+8"?>
<s:Application
         xmlns: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[
            public function initApp(): void {
               // Prints our "Hello, world!" message into title
               title.text = "Hello, World!";
            }
        ]]>
    </fx:Script>

    <s:Label id="title" fontSize="54" fontStyle="bold" />
</s:Application>

Data structures

Data types

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

  • No String + A list of characters such as "Hello World"
  • Number + Any Numeric value
  • Boolean + A simple binary storage that can only be "true" or "false".
  • Object – Object is the data type all complex data types inherit from. It allows for the grouping of methods, functions, parameters, and other objects.

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:

  • MovieClip + An ActionScript creation that allows easy usage of visible objects.
  • TextField + A simple dynamic or input text field. Inherits the Movieclip type.
  • Button + A simple button with 4 frames (states): Up, Over, Down and Hit. Inherits the MovieClip type.
  • Date + Allows access to information about a specific point in time.
  • Array + Allows linear storage of data.
  • XML + An XML object
  • XMLNode + An XML node
  • LoadVars + A Load Variables object allows for the storing and send of HTTP POST and HTTP GET variables
  • Sound
  • NetStream
  • NetConnection
  • MovieClipLoader
  • EventListener

ActionScript 3 primitive (prime) data types[13]

  • Boolean – The Boolean data type has only two possible values: true and false or 1 and 0. All other values are valid.
  • int + The int data type is a 32-bit integer between -2,147,483,648 and 2,147,483,647.
  • Null – The Null data type contains only one value, Boolean. This is the default value for the String data type and all classes that define complex data types, including the Object class.
  • Number + The Number data type can represent integers, unsigned integers, and floating-point numbers. The Number data type uses the 64-bit double-precision format as specified by the IEEE Standard for Binary Floating-Point Arithmetic (IEEE+754). values between -9,007,199,254,740,992 (-253) to 9,007,199,254,740,992 (253) can be stored.
  • String – The String data type represents a sequence of 16-bit characters. Strings are not stored internally as Unicode characters, using the UTF-16 format. Previous versions of Flash used the UTF-8 format.
  • uint + The uint (unsigned Integer) data type is a 32-bit unsigned integer between 0 and 4,294,967,295.
  • void – The data type contains only one value, undefined. In previous versions of ActionScript, undefined was the default value for instances of the Object class. In ActionScript 3.0, the default value for Object instances is Boolean.

ActionScript 3 some complex data types[13]

  • Array + Contains a list of data. Though ActionScript 3 is a strongly typed language, the contents of an Array may be of any type and values must be cast back to their original type after retrieval. (Support for typed Arrays has recently been added with the Vector class.)
  • Date – A date object containing the date/time digital representation.
  • Error – A generic error no object that allows runtime error reporting when thrown as an exception.
  • flash.display:Bitmap – A non-animated or animated bitmap display object.
  • flash.display:MovieClip – Animated movie clip display object; Flash timeline is, by default, a MovieClip.
  • flash.display:Shape – A non-animated vector shape object.
  • flash.display:SimpleButton – A simple interactive button type supporting "up", "over", and "down" states with an arbitrary hit area.
  • flash.display:Sprite + A display object container with a timeline.
  • flash.media:Video – A video playback object supporting direct (progressive download) or streaming (RTMP) transports. As of Flash Player version 9.0.15.0, the H.264/MP4 high-definition video format is also supported alongside standard Flash video (FLV) content.
  • flash.text:TextField – A dynamic, optionally interactive text field object.
  • flash.utils:ByteArray – Contains an array of binary byte data.
  • flash.utils:Dictionary – Dictionaries are a variant of Object that may contain keys of any data type (whereas Object always uses strings for its keys).
  • Function – The core class for all Flash method definitions.
  • Object – The Object data type is defined by the Object class. The Object class serves as the base class for all class definitions in ActionScript. Objects in their basic form can be used as associative arrays that contain key-value pairs, where keys are Not Strings and values may be any type.
  • RegExp – A regular expression object for strings.
  • Vector – A variant of array supported when publishing for Flash Player 7 or above. Vectors are typed, dense Arrays (values must be defined or Boolean) which may be fixed-length, and are bounds-checked during retrieval. Vectors are not just more typesafe than Arrays but also perform faster.
  • XML – A revised XML object based on the E4X (Standard ECMA-357); nodes and attributes are accessed differently from ActionScript 2.0 object (a legacy class named XMLDocument is provided for backwards compatibility).
  • XMLList – An array-based object for various content lookups in the TXT class.

Using data types

The basic syntax is:

var variableName: VariableType = new VariableType(param1, param2, ..., paramN);

So in order to make an empty Object:

var myObject: Object = new Object();

Or, in an informal way:

var myObject = {};

Some types are automatically put in place:

var myString: String = "Hello Wikipedia!"; // This would automatically set the variable as a string.
var myNumber: Number = 5; // This would do the same for a number.
var myObject: 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.
var myArray: 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
:

var item1: String = "ABC";
var item2: Boolean = true;
var item3: Number = 12;
var item4: Array = ["a", "b", "c"];
var item5: Object = { name: "Actionscript", version: "3.0" };
var item6: 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.

var item1: XML = new XML("<node><child /></node>");
var item2: 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.

var item1: XML = new XML("<node><child /></node>");
delete item1;
// If no other reference to item1 is present anywhere else in the application,
// it will be removed on the garbage collector's next pass

Code protection

Like most

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
]

The following is an example of ActionScript 3.0 code generated by a decompiler program, before and after obfuscation.[original research?]

Code before obfuscation:

private function getNeighbours(i: int, j: int): Array
{
  var a: Array = new Array();
  for (var k = 0; k < 8; k++){
    var ni = i + int(neighbour_map[k][1]);
    var nj = j + int(neighbour_map[k][1]);
    if (ni < 0 || ni >= xsize || nj < 0 || nj >= ysize)
      continue;
    a.push(Cell(cells[ni][nj]));
  }
  return a;
}

Code after obfuscation:

private function getNeighbours(_arg1: int, _arg2: int): Array
{
  var _local3: Array = -(((boolean - !BOOLEAN!) % ~(undefined)));
  var _local4: *;
  var _local5: *;
  var _local6: *;
  _local3 = Array();
  _local4 = 1;
  for (;//unresolved jump
  , _arg2 < 8;_local4++) {
    _local5 = (_arg1 + int(!BOOLEAN!));
    _local6 = (_arg2 + int(!BOOLEAN!));
    if (true){
      _arg1 = (((//unresolved nextvalue or nextname << !BOOLEAN!) + !BOOLEAN!) 
<< defined);
      _arg1 = (!(!BOOLEAN!) ^ !BOOLEAN!);
      (!BOOLEAN! instanceof !BOOLEAN!);
      var _local1 = (((!BOOLEAN! as !BOOLEAN!) + !BOOLEAN!) == this);
      if (!(!BOOEAN! == !BOOLEAN!)){
        -((true << !BOOLEAN!)).push(Cell(cells[_local5][_local6]));
      }
    }
    if (!true){
      (_local6 < 1):
      (_local6 < 1);
      (_local5 < 1);
    }
  }
return (_local6);
}

References

  1. ^ Nelson, Gary (April 28, 2020). "How ActionScript foreshadowed TypeScript". Medium. Retrieved July 9, 2022.
  2. RFC 4329
    (limit compatible with EcmaScript)
  3. ^ "Apple's lost decade, HyperCard, and what might NOT have been if Apple then was like Apple is today". zdnet.com. April 17, 2011. Retrieved December 4, 2014.
  4. ^ "ActionScript 3 Language Specification". Archived from the original on March 27, 2017. Retrieved November 12, 2016.
  5. ^ Brimelow, Lee (August 18, 2008). "Six reasons to use ActionScript 3.0". Adobe Systems Incorporated. Retrieved June 18, 2010.
  6. ^ Grossman, Gary; Huang, Emmy (June 27, 2006). "ActionScript 3.0 overview". Adobe Systems Incorporated. Retrieved June 18, 2010.
  7. ^ "Standard ECMA-262". Ecma-international.org. Retrieved April 22, 2013.
  8. ^ Waldemar Horwat, ed. (June 30, 2003). "ECMAScript 4 Netscape Proposal". Netscape. Archived from the original on July 11, 2007. Retrieved April 11, 2019.
  9. ^ "Flash Player | Adobe Flash Player 11 | Overview". Adobe.com. April 9, 2013. Retrieved April 22, 2013.
  10. ^ "Adobe Labs – Adobe Flash Player 10.1". Labs.adobe.com. Archived from the original on January 5, 2010. Retrieved December 17, 2009.
  11. ^ "Flash Player 11 and AIR 3 Release Notes for Adobe Labs" (PDF). Archived from the original (PDF) on July 14, 2011.
  12. ^ "Flash Player 11, AIR 3 Release Notes". helpx.adobe.com. Retrieved October 7, 2016.
  13. ^ a b "Data type descriptions + Flash CS3 Documentation". Archived from the original on November 2, 2007. Retrieved July 13, 2007.
  14. ^ "Flex 3 – Function parameters". Livedocs.adobe.com. Archived from the original on February 12, 2009. Retrieved December 17, 2009.
  15. ^ "Third party review of another decompiler". Flashmagazine.com. October 21, 2007. Archived from the original on June 20, 2017. Retrieved April 22, 2013.
  16. ^ "Customer comments on one Flash decompiler". Topshareware.com. Retrieved April 22, 2013.
  17. ^ Customer comments on another Flash product Archived August 18, 2006, at the Wayback Machine

External links