Home      Discussion      Topics      Dictionary      Almanac
Signup       Login
ActionScript

ActionScript

Overview
ActionScript is a scripting language based on ECMAScript
ECMAScript
ECMAScript is a scripting language, standardized by Ecma International in the ECMA-262 specification and ISO/IEC 16262. The language is widely used on the web, especially in the form of its three best-known dialects, JavaScript, ActionScript, and JScript.-History:JavaScript was originally developed...

. ActionScript is used primarily for the development of websites and software using the Adobe Flash Player
Adobe Flash Player
The Adobe Flash Player is software for viewing animations and movies using computer programs such as a web browser; in common usage, Flash lets you put animation and movies on a web site. Flash player is a widely distributed proprietary multimedia and application player created by Macromedia and...

 platform (in the form of SWF files embedded into Web page
Web page
A webpage or web page is a document or resource of information that is suitable for the World Wide Web and can be accessed through a web browser and displayed on a computer screen....

s), but is also used in some database applications (such as Alpha Five
Alpha Five
Alpha Five is a relational database management system and Rapid Application Development system for building Windows desktop and Web applications....

), and in basic robotics, as with the Make Controller Kit. Originally developed by Macromedia
Macromedia
Macromedia was a North American graphics and Web development software house headquartered in San Francisco, California producing such products as Macromedia Flash as well as Macromedia Dreamweaver...

, the language is now owned by Adobe
Adobe Systems
Adobe Systems Incorporated is an American computer software company headquartered in San Jose, California, USA. The company has historically focused upon the creation of multimedia and creativity software products, with a more-recent foray towards rich Internet application software...

 (which acquired Macromedia in 2005).
Discussion
Ask a question about 'ActionScript'
Start a new discussion about 'ActionScript'
Answer questions from other users
Full Discussion Forum
 
Encyclopedia
ActionScript is a scripting language based on ECMAScript
ECMAScript
ECMAScript is a scripting language, standardized by Ecma International in the ECMA-262 specification and ISO/IEC 16262. The language is widely used on the web, especially in the form of its three best-known dialects, JavaScript, ActionScript, and JScript.-History:JavaScript was originally developed...

. ActionScript is used primarily for the development of websites and software using the Adobe Flash Player
Adobe Flash Player
The Adobe Flash Player is software for viewing animations and movies using computer programs such as a web browser; in common usage, Flash lets you put animation and movies on a web site. Flash player is a widely distributed proprietary multimedia and application player created by Macromedia and...

 platform (in the form of SWF files embedded into Web page
Web page
A webpage or web page is a document or resource of information that is suitable for the World Wide Web and can be accessed through a web browser and displayed on a computer screen....

s), but is also used in some database applications (such as Alpha Five
Alpha Five
Alpha Five is a relational database management system and Rapid Application Development system for building Windows desktop and Web applications....

), and in basic robotics, as with the Make Controller Kit. Originally developed by Macromedia
Macromedia
Macromedia was a North American graphics and Web development software house headquartered in San Francisco, California producing such products as Macromedia Flash as well as Macromedia Dreamweaver...

, the language is now owned by Adobe
Adobe Systems
Adobe Systems Incorporated is an American computer software company headquartered in San Jose, California, USA. The company has historically focused upon the creation of multimedia and creativity software products, with a more-recent foray towards rich Internet application software...

 (which acquired Macromedia in 2005). ActionScript was initially designed for controlling simple 2D vector animations made in Adobe Flash
Adobe Flash
Adobe Flash is a multimedia platform originally acquired by Macromedia and currently developed and distributed by Adobe Systems. Since its introduction in 1996, Flash has become a popular method for adding animation and interactivity to web pages...

 (formerly Macromedia Flash). Later versions added functionality allowing for the creation of Web-based games and rich Internet application
Rich Internet application
Rich Internet applications are web applications that have most of the characteristics of desktop applications, typically delivered by way of standards based web browser plug-ins or independently via sandboxes or virtual machines...

s with streaming media (such as video and audio).

History


ActionScript started as a scripting language
Scripting language
A scripting language, script language or extension language is a programming language that allows control of one or more software applications. "Scripts" are distinct from the core code of the application, which is usually written in a different language, and are often created or at least modified...

 for Macromedia
Macromedia
Macromedia was a North American graphics and Web development software house headquartered in San Francisco, California producing such products as Macromedia Flash as well as Macromedia Dreamweaver...

's Flash authoring tool, now developed by Adobe Systems
Adobe Systems
Adobe Systems Incorporated is an American computer software company headquartered in San Jose, California, USA. The company has historically focused upon the creation of multimedia and creativity software products, with a more-recent foray towards rich Internet application software...

 as Adobe Flash
Adobe Flash
Adobe Flash is a multimedia platform originally acquired by Macromedia and currently developed and distributed by Adobe Systems. Since its introduction in 1996, Flash has become a popular method for adding animation and interactivity to web pages...

. 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
Scripting language
A scripting language, script language or extension language is a programming language that allows control of one or more software applications. "Scripts" are distinct from the core code of the application, which is usually written in a different language, and are often created or at least modified...

. New capabilities introduced for Flash 4 included variables
Variable (programming)
In computer programming, a variable is a facility for storing data. The current value of the variable is the data actually stored in the variable. Depending on the programming language in question, the data stored in the variable can be intentionally altered during the program run. This is why it...

, expressions
Expression (programming)
An expression in a programming language is a combination of values, variables, operators, and functions that are interpreted according to the particular rules of precedence and of association for a particular programming language, which computes and then produces another value...

, operators
Operator (programming)
Programming languages generally support a set of operators that are similar to operators in mathematics. A language may contain a fixed number of built-in operators , or it may allow the creation of programmer-defined operators Programming languages generally support a set of operators that are...

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

Timeline by player

  • Flash Player 2: The first version with scripting support. Actions included gotoAndPlay, gotoAndStop, nextFrame and nextScene for timeline control.
  • Flash Player 3: Expanded basic scripting support with the ability to load external SWF
    SWF
    The file formatSWF a partially open repository for multimedia and especially for vector graphics, originated with FutureWave Software and...

    s (loadMovie).
  • Flash Player 4: First player with a full scripting implementation (called Actions). The scripting was a flash based syntax and contained support for loops, conditionals, variables and other basic language constructs.
  • Flash Player 5: Included the first version of ActionScript. Used prototype-based programming
    Prototype-based programming
    Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior reuse is performed via a process of cloning existing objects that serve as prototypes...

     based on ECMAScript, and allowed full procedural programming
    Procedural programming
    Procedural programming can sometimes be used as a synonym for imperative programming , but can also refer to a programming paradigm based upon the concept of the procedure call...

     and object-oriented programming
    Object-oriented programming
    Object-oriented programming is a programming paradigm that uses "objects" – data structures consisting of datafields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as information hiding, data...

    .
  • Flash Player 6: Added an event handling model, accessibility controls and support for switch
    Switch statement
    In computer programming, a switch statement is a type of control statement that exists in most modern imperative programming languages . Its purpose is to allow the value of a variable or expression to control the flow of program execution...

    . The first version with support for the AMF
    Action Message Format
    Action Message Format or AMF is a binary format based loosely on the Simple Object Access Protocol . It is used primarily to exchange data between an Adobe Flash application and a database, using a Remote Procedure Call....

     and RTMP
    Real Time Messaging Protocol
    Real Time Messaging Protocol is a proprietary protocol developed by Adobe Systems for streaming audio, video and data over the Internet, between a Flash player and a server.The RTMP protocol has three variations:...

     protocols which allowed for ondemand audio/video streaming.
  • Flash Player 7: Additions include CSS styling for text and support for ActionScript 2.0, a programming language based on the ECMAScript 4 Netscape Proposal with class
    Class (computer science)
    In object-oriented programming, a class is a construct that is used as a blueprint to create objects of that class. This blueprint describes the state and behavior that the objects of the class all share. An object of a given class is called an instance of the class. The class that contains that...

    -based inheritance
    Inheritance (computer science)
    In object-oriented programming, inheritance is a way to form new classes using classes that have already been defined. Inheritance is intended to help reuse existing code with little or no modification...

    . However, ActionScript 2.0 can cross compile to ActionScript 1.0 byte-code, so that it can run in Flash Player 6.
  • Flash Player 8: Further extended ActionScript 1/ActionScript 2 by adding new class libraries with APIs for controlling bitmap data at run-time, file uploads and live filters for blur and dropshadow.
  • Flash Player 9 (initially called 8.5): Added ActionScript 3.0 with the advent of a new virtual machine, called AVM2 (ActionScript Virtual Machine 2), which coexists with the previous AVM1 needed to support legacy content. Performance increases were a major objective for this release of the player including a new JIT compiler. Support for binary sockets, E4X
    E4X
    ECMAScript for XML is a programming language extension that adds native XML support to ECMAScript . The goal is to provide an alternative to DOM interfaces that uses a simpler syntax for accessing XML documents. It also offers a new way of making XML visible...

     XML parsing, full-screen mode and Regular Expressions were added. This is the first release of the player to be titled Adobe Flash Player.
  • Flash Player 10 (initially called Astro): Added basic 3D
    3D computer graphics
    3D computer graphics are graphics that use a three-dimensional representation of geometric data that is stored in the computer for the purposes of performing calculations and rendering 2D images...

     manipulation, such as rotating on the X, Y, and Z axis, and a 3D drawing API. Ability to create custom filters using Adobe Pixel Bender
    Adobe Pixel Bender
    Adobe Pixel Bender, previously codenamed Hydra is a programming language created by Adobe Systems for the description of image processing algorithms...

    . Several visual processing tasks are now offloaded to the GPU which gives a noticeable decrease to rendering time for each frame, resulting in higher frame rate
    Frame rate
    Frame rate, or frame frequency, is the measurement of the frequency at which an imaging device produces unique consecutive images called frames. The term applies equally well to computer graphics, video cameras, film cameras, and motion capture systems...

    s, especially with H.264 video. There is a new sound API which allows for custom creation of audio in flash, something that has never been possible before. Furthermore, Flash Player 10 supports Peer to Peer (P2P) communication with Real Time Media Flow Protocol
    Real Time Media Flow Protocol
    Real Time Media Flow Protocol is a proprietary protocol developed by Adobe Systems. RTMFPenables direct peer-to-peer communication between multiple Adobe Flash Players...

     (RTMFP).

Timeline by ActionScript version


2000–2003: 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. This was the first version of ActionScript with influences from JavaScript
JavaScript
JavaScript is an object-oriented scripting language used to enable programmatic access to objects within both the client application and other applications. It is primarily used in the form of client-side JavaScript, implemented as an integrated component of the web browser, allowing the...

 and the ECMA-262 (Third Edition) standard, supporting the said standard's object model and many of its core data type
Data type
A data type in programming languages is a set of values and the operations on those values.-Overview:Almost all programming languages explicitly include the notion of data type, though different languages may use different terminology...

s. Local variables
Variable (programming)
In computer programming, a variable is a facility for storing data. The current value of the variable is the data actually stored in the variable. Depending on the programming language in question, the data stored in the variable can be intentionally altered during the program run. This is why it...

 may be declared with the var statement, and user-defined functions with parameter
Parameter (computer science)
In computer programming, a parameter is a special kind of variable, used in a subroutine to refer to one of the pieces of data provided as input to the subroutine.. These pieces of data are called arguments...

 passing and return
Return statement
In computer programming, a return statement causes execution to leave the current subroutine and resume at the point in the code immediately after where the subroutine was called — known as its return address. The return address is saved, usually on the process's call stack, as part of the...

 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
Adobe Flash Player
The Adobe Flash Player is software for viewing animations and movies using computer programs such as a web browser; in common usage, Flash lets you put animation and movies on a web site. Flash player is a widely distributed proprietary multimedia and application player created by Macromedia and...

, 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
Inheritance (computer science)
In object-oriented programming, inheritance is a way to form new classes using classes that have already been defined. Inheritance is intended to help reuse existing code with little or no modification...

. Loose typing refers to the ability of a variable
Variable (programming)
In computer programming, a variable is a facility for storing data. The current value of the variable is the data actually stored in the variable. Depending on the programming language in question, the data stored in the variable can be intentionally altered during the program run. This is why it...

 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
Object-oriented programming
Object-oriented programming is a programming paradigm that uses "objects" – data structures consisting of datafields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as information hiding, data...

. Instead of a class keyword that defines common characteristics of a class
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create objects of that class. This blueprint describes the state and behavior that the objects of the class all share. An object of a given class is called an instance of the class. The class that contains that...

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

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, Flash Player 7
Adobe Flash Player
The Adobe Flash Player is software for viewing animations and movies using computer programs such as a web browser; in common usage, Flash lets you put animation and movies on a web site. Flash player is a widely distributed proprietary multimedia and application player created by Macromedia and...

. 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
Syntax of programming languages
In computer science, the syntax of a programming language is the set of rules that define the combinations of symbols that are considered to be correctly structured programs in that language. The syntax of a language defines its surface form...

, 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
Bytecode
Bytecode is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software interpreter as well as being suitable for further compilation into machine code...

, allowing it to be used on the preceding Flash Player 6 as well.
In other words, the class-based
Class-based programming
Class-based programming, or more commonly class-orientation, refers to the style of object-oriented programming in which inheritance is achieved by defining classes of objects, as opposed to the objects themselves .The most popular and developed model of OOP is a class-based model, as opposed to an...

 inheritance syntax
Syntax of programming languages
In computer science, the syntax of a programming language is the set of rules that define the combinations of symbols that are considered to be correctly structured programs in that language. The syntax of a language defines its surface form...

 was a layer on top of the existing prototype-based
Prototype-based programming
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior reuse is performed via a process of cloning existing objects that serve as prototypes...

 system.) With ActionScript 2.0, developers could constrain variables
Variable (programming)
In computer programming, a variable is a facility for storing data. The current value of the variable is the data actually stored in the variable. Depending on the programming language in question, the data stored in the variable can be intentionally altered during the program run. This is why it...

 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
Syntax of programming languages
In computer science, the syntax of a programming language is the set of rules that define the combinations of symbols that are considered to be correctly structured programs in that language. The syntax of a language defines its surface form...

 so that developers could create classes and interfaces, much as they would in class-based languages such as Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

 and C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features...

. This version conformed partially to the ECMAScript
ECMAScript
ECMAScript is a scripting language, standardized by Ecma International in the ECMA-262 specification and ISO/IEC 16262. The language is widely used on the web, especially in the form of its three best-known dialects, JavaScript, ActionScript, and JScript.-History:JavaScript was originally developed...

 Fourth Edition draft specification.

2006–today: ActionScript 3.0
In June 2006, ActionScript 3.0 debuted with Adobe Flex 2.0
Adobe Flex
Adobe Flex is a software development kit released by Adobe Systems for the development and deployment of cross-platform rich Internet applications based on the Adobe Flash platform...

 and its corresponding player, Flash Player 9
Adobe Flash Player
The Adobe Flash Player is software for viewing animations and movies using computer programs such as a web browser; in common usage, Flash lets you put animation and movies on a web site. Flash player is a widely distributed proprietary multimedia and application player created by Macromedia and...

. ActionScript 3.0 was a fundamental restructuring of the language, so much so that it uses an entirely different virtual machine
Virtual machine
A virtual machine is a software implementation of a machine that executes programs like a physical machine.-Definitions:...

. Flash Player 9
Adobe Flash Player
The Adobe Flash Player is software for viewing animations and movies using computer programs such as a web browser; in common usage, Flash lets you put animation and movies on a web site. Flash player is a widely distributed proprietary multimedia and application player created by Macromedia and...

 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
DirectX
Microsoft DirectX is a collection of application programming interfaces for handling tasks related to multimedia, especially game programming and video, on Microsoft platforms. Originally, the names of these APIs all began with Direct, such as Direct3D, DirectDraw, DirectMusic, DirectPlay,...

, OpenGL
OpenGL
OpenGL is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL...

).

The update to the language introduced several new features:
  • Compile-time and runtime type checking—type information exists at both compile-time and runtime.
  • Improved performance from a class-based inheritance system separate from the prototype-based inheritance system.
  • Support for packages
    Java package
    A Java package is a mechanism for organizing Java classes into namespaces similar to the modules of Modula. Java packages can be stored in compressed files called JAR files, allowing classes to download faster as a group rather than one at a time...

    , namespaces
    Namespace (computer science)
    A namespace is an abstract container or environment created to hold a logical grouping of unique identifiers or symbols . An identifier defined in a namespace is associated with that namespace. The same identifier can be independently defined in multiple namespaces...

    , and regular expressions.
  • Compiles to an entirely new type of bytecode
    Bytecode
    Bytecode is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software interpreter as well as being suitable for further compilation into machine code...

    , incompatible with ActionScript 1.0 and 2.0 bytecode
    Bytecode
    Bytecode is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software interpreter as well as being suitable for further compilation into machine code...

    .
  • Revised Flash Player API, organized into packages
    Java package
    A Java package is a mechanism for organizing Java classes into namespaces similar to the modules of Modula. Java packages can be stored in compressed files called JAR files, allowing classes to download faster as a group rather than one at a time...

    .
  • Unified event handling system based on the DOM event handling
    DOM Events
    DOM events allow event-driven programming languages like JavaScript, JScript, ECMAScript, VBScript and Java to register various event handlers/listeners on the element nodes inside a DOM tree, e.g. HTML, XHTML, XUL and SVG documents....

     standard.
  • Integration of ECMAScript
    ECMAScript
    ECMAScript is a scripting language, standardized by Ecma International in the ECMA-262 specification and ISO/IEC 16262. The language is widely used on the web, especially in the form of its three best-known dialects, JavaScript, ActionScript, and JScript.-History:JavaScript was originally developed...

     for XML (E4X
    E4X
    ECMAScript for XML is a programming language extension that adds native XML support to ECMAScript . The goal is to provide an alternative to DOM interfaces that uses a simpler syntax for accessing XML documents. It also offers a new way of making XML visible...

    ) for purposes of XML
    XML
    XML is a set of rules for encoding documents electronically. It is defined in the produced by the W3C and several other related specifications; all are fee-free open standards....

     processing.
  • Direct access to the Flash runtime display list for complete control of what gets displayed at runtime.
  • Completely conforming implementation of the ECMAScript
    ECMAScript
    ECMAScript is a scripting language, standardized by Ecma International in the ECMA-262 specification and ISO/IEC 16262. The language is widely used on the web, especially in the form of its three best-known dialects, JavaScript, ActionScript, and JScript.-History:JavaScript was originally developed...

     fourth edition draft specification.

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
    FLV
    Flash Video is a container file format used to deliver video over the Internet using Adobe Flash Player versions 6–10. Flash Video content may also be embedded within SWF files. There are two different video file formats defined by Adobe Systems and supported in Adobe Flash Player: FLV and F4V...

     video playback.

Syntax


ActionScript code is free form
Free-form language
In computer programming, a free-form language is a programming language in which the positioning of characters on the page in program text is not significant. Program text does not need to be placed in specific columns as on old punched card systems, and frequently ends of lines are not significant...

 and thus may be created with whichever amount or style of whitespace that the author desires. The basic syntax is derived from ECMAScript
ECMAScript
ECMAScript is a scripting language, standardized by Ecma International in the ECMA-262 specification and ISO/IEC 16262. The language is widely used on the web, especially in the form of its three best-known dialects, JavaScript, ActionScript, and JScript.-History:JavaScript was originally developed...

.

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 {}
public function onLoad :Void
{
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 greet:TextField = new TextField;
greet.text = "Hello World";
this.addChild(greet);


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";
addChild(txtHello);
}
}
}

(See also: Sprite
Sprite (computer graphics)
In computer graphics, a sprite is a two-dimensional/three-dimensional image or animation that is integrated into a larger scene....

)

Finally, an example of using ActionScript when developing Flex
Adobe Flex
Adobe Flex is a software development kit released by Adobe Systems for the development and deployment of cross-platform rich Internet applications based on the Adobe Flash platform...

 applications, again presuming the following content to be in a file named Greeter.as:

package
{
public class Greeter
{
public static function sayHello:String
{
var greet:String = "Hello, world!";
return greet;
}
}
}


This code will work with the following MXML
MXML
MXML is a XML-based user interface markup language first introduced by Macromedia in March 2004. Adobe Systems gives no official meaning for the acronym, but some developers suggest it should stand for "Magic eXtensible Markup Language"...

 application file:





public function initApp:void
{
// Prints our "Hello, world!" message into "mainTxt".
mainTxt.text = Greeter.sayHello;
}
]]>







Data types
ActionScript primarily consists of "fundamental" or "simple" data types which 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
  • 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
(see Data type descriptions)
  • Boolean - The Boolean data type has only two possible values: true and false or 1 and 0. No 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, null. 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).
  • String - The String data type represents a sequence of 16-bit characters. Strings are 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 void 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 null.


ActionScript 3 some complex data types
(see Data type descriptions)
  • 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 array
    Associative array
    An associative array is an abstract data type composed of a collection of unique keys and a collection of values, where each key is associated with one value...

    s that contain key-value pairs, where keys are Strings and values may be any type.
  • 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.)
  • Vector - A variant of array supported only when publishing for Flash Player 10 or above. Vectors are typed, dense Arrays (values must be defined or null) which may be fixed-length, and are bounds-checked during retrieval. Vectors are not just more typesafe than Arrays but also perform faster.
  • 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).
  • flash.display:MovieClip - Animated movie clip display object; Flash timeline if is by default a MovieClip.
  • flash.display:Bitmap - A non-animated bitmap display object.
  • flash.display:Shape - A non-animated vector shape object.
  • flash.utils:ByteArray - Contains an array of binary byte data.
  • flash.text:TextField - A dynamic, optionally interactive text field object.
  • flash.display:SimpleButton - A simple interactive button type supporting "up", "over", and "down" states with an arbitrary hit area.
  • Date - A date object containing the date/time digital representation.
  • Error - A generic error object that allows runtime error reporting when thrown as an exception.
  • Function - The core class for all Flash method definitions.
  • RegExp - A regular expression object for strings.
  • flash.media:Video - A video playback object supporting direct (progressive download) or streaming (RTMP) transports. As of Flash Player version 9.0.115.0, the H.264/MP4 high-definition video format is also supported along side standard Flash video (FLV) content.
  • XML - A revised XML object based on the E4X (Standard ECMA-357); nodes and attributes are accessed differently than 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 XML class.

Using data types
The basic syntax is:

var yourVariableName:YourVariableType = new YourVariableType(Param1, Param2, ..., ParamN);

So in order to make an empty Object:

var myObject:Object = new Object;

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.
var myArray:Array = [5,"Hello!",{a:5, b:7}] //This is the syntax for automatically creating an Array.
//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 most object-oriented languages, ActionScript makes no distinction between primitive
Primitive type
In computer science, primitive data type can refer to either of the following concepts:* a basic type is a data type provided by a programming language as a basic building block...

 types and reference
Reference (computer science)
In computer science, a reference is a value that enables a program to directly access a particular data item, such as a variable or a record, in the computer's memory or in some other storage device. The reference is said to refer to the data item, and accessing that data is called dereferencing...

 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, have special operators that make them behave as if they were passed by value.

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 (passed by value). If a variable of an other (not primitive) datatype, e.g. XML is passed to a function, altering that variable inside the function will alter the original variable as well (passed by reference).

Some data types can be assigned values with literals
Object literal
In computer science, a literal is a notation for representing a fixed value in source code. Almost all programming languages have notations for atomic values such as integers, floating-point numbers, strings, and booleans; some also have notations for elements of enumerated types and compound...

:

var item1:String="ABC";
var item2:Boolean=true;
var item3:Number=12;
var item4:Array=["a","b","c"];
var item5:XML = ; //Note that the primitive XML is not quoted

A reference in ActionScript is a pointer to an instance of a class. This does not create a copy but accesses the same memory space. All objects in ActionScript are accessed as references instead of being copied.

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

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("");
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

See also

  • ECMAScript
    ECMAScript
    ECMAScript is a scripting language, standardized by Ecma International in the ECMA-262 specification and ISO/IEC 16262. The language is widely used on the web, especially in the form of its three best-known dialects, JavaScript, ActionScript, and JScript.-History:JavaScript was originally developed...

     — The standardized scripting language upon which ActionScript is based.
  • Adobe Flash
    Adobe Flash
    Adobe Flash is a multimedia platform originally acquired by Macromedia and currently developed and distributed by Adobe Systems. Since its introduction in 1996, Flash has become a popular method for adding animation and interactivity to web pages...

     — The program in which ActionScript debuted.
  • Adobe Flash Player
    Adobe Flash Player
    The Adobe Flash Player is software for viewing animations and movies using computer programs such as a web browser; in common usage, Flash lets you put animation and movies on a web site. Flash player is a widely distributed proprietary multimedia and application player created by Macromedia and...

     — The official and most widely used SWF player.
  • Adobe Flash Lite — A miniature version of the Flash Player for mobile devices.
  • Adobe AIR - Runtime for ActionScript/Flex
  • Adobe Flex
    Adobe Flex
    Adobe Flex is a software development kit released by Adobe Systems for the development and deployment of cross-platform rich Internet applications based on the Adobe Flash platform...

     - SDK and IDE which uses ActionScript
  • SWF File Format
    SWF
    The file formatSWF a partially open repository for multimedia and especially for vector graphics, originated with FutureWave Software and...

  • Tamarin (JIT)
  • Macromedia
    Macromedia
    Macromedia was a North American graphics and Web development software house headquartered in San Francisco, California producing such products as Macromedia Flash as well as Macromedia Dreamweaver...

  • Adobe Systems
    Adobe Systems
    Adobe Systems Incorporated is an American computer software company headquartered in San Jose, California, USA. The company has historically focused upon the creation of multimedia and creativity software products, with a more-recent foray towards rich Internet application software...

  • Gnash
    Gnash
    Gnash is the GNU SWF movie player, which can be run standalone on a computer or an embedded device, as well as as a plugin for several browsers. It is a part of the GNU Project that aims to create a free software player and browser plugin for the Adobe Flash file format...

    , a free Flash viewer
  • Swfdec
    Swfdec
    Swfdec is a free/open source replacement of Adobe Flash Player. It is currently compatible with Linux and FreeBSD and is distributed under the terms of the GNU Lesser General Public License ....

  • Adobe Flex Builder
    Adobe Flex Builder
    Adobe Flash Builder 4 , is an integrated development environment built on the Eclipse platform meant for developing rich Internet applications and cross-platform desktop applications, particularly for the Adobe Flash platform...

     - IDE by Adobe to author ActionScript
  • HaXe
    HaXe
    haXe is a programming language, designed for creating interactive web applications. Currently there are five official compiler targets: Adobe Flash, JavaScript, PHP, C++ Source Files and the Neko VM.-History:...


Adobe documentation and references
Tutorials and references


Developer tools
  • Adobe Flash Professional (i.e. the Flash IDE)
  • Adobe Flex SDK
  • FlashDevelop - Popular open-source ActionScript IDE
  • swftools' as3compile - as3compile, a free compiler for ActionScript 3.0
  • Motion Twin ActionScript Compiler - MTASC
    MTASC
    MTASC is an ActionScript 2.0 compiler written in the Objective Caml programming language by the company Motion-Twin. It is free software and can be used alone or with other tools like swfmill to produce SWF files, which contain interactive multimedia content playable with the Flash Player...

    is an Open-source ActionScript 2 compiler