ActionScript is an object-oriented programming language , one of the ECMAScript dialects that adds interactivity, data processing, and much more to the contents of Flash applications. ActionScript is executed by the virtual machine (ActionScript Virtual Machine), which is part of Flash Player. ActionScript is compiled into bytecode , which is included in the SWF file.
| ActionScript | |
|---|---|
| Language class | Object Oriented , Prototype , Imperative , Script |
| Appeared in | 1998 |
| Author | Harry grossman |
| Developer | |
| Release | 3.0 |
| Type system | strong , static |
| Key implementations: | Adobe Flash Player , Adobe AIR , Apache Flex |
| Influenced | Javascript java |
| Site | |
| ActionScript | |
|---|---|
| MIME type | application / ecmascript [1] |
| Developer | |
| Format type | , and |
| Site | |
SWF files are executed by Flash Player. Flash Player exists as a plug-in for a web browser , as well as a standalone application (standalone). In the second case, it is possible to create executable exe files (projector) when the Flash Player application is combined with a swf file by analogy with SFX .
With ActionScript, you can create interactive multimedia applications, games , websites, and more.
ActionScript is an open programming language, its specification is publicly available on the Adobe website [2] . The compiler (as part of Apache Flex ) and the open virtual machine ( Tamarin ) are open source software .
Content
History
ActionScript as a language appeared with the release of the 5th version of Macromedia Flash , which became the first ActionScript-programmed environment. The first released version of the language was called ActionScript 1.0. The 6th version of Flash (MX) also used ActionScript 1.0. In 2004, Macromedia introduced a new version of ActionScript 2.0 along with the release of Flash 7 (MX 2004), which introduced strong typedefinition, as well as class-based programming. That is, new keywords appeared:
- class
- interface
- extends (setting inheritance)
- access modifiers: private, public;
- and others.
Also, Macromedia has released a modification of the Flash Lite language for programming for mobile phones.
ActionScript 1.0 is a prototype programming language . That is, it fully implements all three principles of object-oriented programming.
ActionScript 2.0 is an add-on for ActionScript 1.0. Type checking and working with the class hierarchy is performed at compile time, which ends with the generation of a bytecode similar to ActionScript 1.0.
In 2006, ActionScript 3.0 was released in the Adobe Flex programming environment, and later in Adobe Flash 9.
ActionScript 3.0 represents, compared with ActionScript 2.0, a qualitative change, it uses the new AVM 2.0 virtual machine and, instead of the previous formal class syntax, provides object-oriented class-based programming . ActionScript 3.0 provides up to 700 times faster performance compared to ActionScript 1.0 / 2.0 (this is just processing instructions without affecting the graphics). ActionScript 3.0 allows you to work with binary data, with BitMap (which provides a significant performance increase: up to 10,000 times). ActionScript 3.0 is close in speed to programming languages such as Java and C # . Performance increase based on dynamic code translation ( JIT ). Such an increase in performance is possible only for certain types of data and requires special organization of the code [3] . The amount of code, as a rule, increases several times [4] (compared with AS1)
| Player versions | Innovations |
|---|---|
| 2 | “Actions” appeared, hereinafter known as:
|
| 3 | The advent of loadMovie (); |
| four | The first version with full support for script implementation. |
| five | The first version of ActionScript appeared. We used prototype programming based on ECMAScript and provided full support for procedural and object-oriented programming. |
| 6 |
|
| 7 |
|
| eight |
|
| 9 |
|
| ten |
|
| 10.2 |
|
| eleven |
|
| Support for ActionScript versions: | |||
|---|---|---|---|
| Not supported | AS1 | AS1, AS2 | AS1, AS2, AS3 |
Syntax
The ActionScript syntax is based on the ECMAScript specification.
ActionScript 2.0
This code creates a new text field, at a depth of 0, at a point (0, 0) and a size of 100 per 100 pixels. The text parameter is equal to the string “ Hello, world ”. The code should be written in the action - frame window
createTextField ( "greet" , 0 , 0 , 0 , 100 , 100 );
greet . text = "Hello world!" ;
An example class written in AS2. The code should be stored in a separate .as file and located in the same folder with the project .fla source.
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 Ako!" ;
}
}
ActionScript 3.0
In the source code of the compiled Adobe Flex SDK (AS 3.0):
package {
import flash . display . Sprite
import flash . text . TextField
public class HelloWorld extends Sprite {
public function HelloWorld () {
var txtHello : TextField = new TextField ();
txtHello . text = "Hello world!" ;
addChild ( txtHello );
}
}
MXML
Code written in MXML (XML extension):
<? xml version = "1.0" encoding = "utf-8"?>
<mx: Application xmlns: mx = "http://www.adobe.com/2006/mxml" xmlns = "*" layout = "vertical"
creationComplete = "initApp ()" >
<mx: Script>
<! [CDATA [
public function initApp (): void
{
// Prints our "Hello, world!" message into "mainTxt".
mainTxt.text = Greeter.sayHello ();
}
]]>
</ mx: Script>
<mx: Label id = "title" fontSize = "24" fontStyle = "bold" text = '"Hello, world!" Example ' />
<mx: TextArea id = "mainTxt" width = "250" />
</ mx: Application>
Debugger
An example of a debugger. Displays output of any data that can be converted to String (AS2 and beyond):
trace ( "Hello world!" );
Structure
ActionScript 2
Elementary Data Types
| Type of | Description |
|---|---|
| String | A string, an array of characters, for example: “Hello World” |
| Number | Any numeric value, for example: 0, 0.5, 1150 |
| Boolean | Boolean, can be either true or false. |
| Object | An object. An example of an object is classes, methods, functions, parameters ... |
Complex data types
| Type of | Description |
|---|---|
| Movieclip | A graphic containing frames. |
| Textfield | A dynamic or input text field. |
| Button | Button. It is essentially a Movie Clip with a predefined behavior. Consists of 4 frames: Up, Over, Down and Hit. |
| Date | An object containing date / time information. |
| Array | Data array. |
| XML | XML object |
| XMLNode | Xml node |
| Loadvars | Serves for sending and receiving variables using HTTP POST and HTTP GET |
| Sound | Contains sound data .MP3 format |
| Netstream | Contains audio data of other formats |
| Netconnection | Allows 2 flash movies to interact in the same scope (for example, on the desktop, or in one browser tab) |
| MovieClipLoader | Class for loading swf clips and .jpg .png images |
| Eventlistener | Event handler |
ActionScript 3
Elementary Data Types
(see Adobe documentation )
| Type of | Description |
|---|---|
| Boolean | Boolean, can be either true or false. |
| int | an integer 32-bit numerical value in the range from −2 31 to 2 31 −1. |
| uint | an integer 32-bit numeric value in the range 0 to 2 32 −1. |
| Number | fractional 64-bit numerical value in the range from −2 63 to 2 63 −1. |
| null | zero. Link to the void. |
| String | A string of 16-bit characters. The encoding is UTF-16. |
| void | a single value data type is undefined. Used if the programmer wants to indicate the type of function as "non-returnable". |
Complex data types
(see Adobe documentation )
| Type of | Description |
|---|---|
| Object | An object. The key class of OOP. It is the basis of all AS3 classes. |
| Array | Array of data of weak typing. It can take any values, for example: ['a', 5, new TextField ()] |
| Vector | An array of strongly typed data. For example, the Vector. <String> array can contain only string data ['a', 'b', ''] |
| Date | A class containing date / time information. |
| Error | The class containing the errors. |
| Function | Main class. An example is any AS3 method. |
| Regexp | Regular expressions |
| XML | E4X-based XML object (ECMA-357 standard) |
| XMLList | Array-based object for finding content in an XML class. |
Packages
ActionScript 3.0 (or rather Flash Player 9 API - you can say the standard library written in C ++) consists of more than 700 classes organized in the following packages (analogs of namespaces in C ++):
| Package | Description |
|---|---|
| flash.accessibility | classes to support access to Flash content and applications. |
| flash.display | The main classes that Flash Player uses to display images. |
| flash.errors | commonly used error handling classes. |
| flash.external | contains the ExternalInterface class, which is used to communicate with the Flash Player container. |
| flash.filters | classes for working with raster image filters. |
| flash.geom | classes for working with geometric classes, such as points, rectangles and transformation matrices, to support the BitmapData class and the ability to cache images. |
| flash.media | classes for working with multimedia - for example, sounds and videos. |
| flash.net | classes for sending and receiving data over the network. For example, URL requests and Flash Remoting. |
| flash.printing | classes for printing the contents of a Flash movie. |
| flash.profiler | functions used for debugging and profiling code. |
| flash.system | classes for accessing the system at the level of functionality, such as security, multilingual content, etc. |
| flash.text | classes for working with text, its formatting, size, style and layout. |
| flash.ui | user interface classes, such as mouse and keyboard classes. |
| flash.utils | additional classes, such as ByteArray for working with binary data, Timer for counting time intervals, etc. |
| flash.xml | provides XML support and all the functions for working with XML. (Needed to support previous versions of AS) |
There are also mx. * Packages, which consist of classes designed to create an application interface in the Flex environment and fl. * Packages for the Flash environment
Popular Media
- Adobe Flash - Historically the first environment to support AS. Starting with Flash 5, the ACTIONS panel appeared, with the ability to edit code (AS1). For Flash 6, AS2 was created. Starting with Flash 9, support for AS3 appeared.
- Adobe Flash Builder - A development environment for creating RIA applications for desktop and mobile devices.
- Powerflasher FDT - An environment recognized by experienced flash programmers, is based on eclipse - a free integrated development environment for modular cross-platform applications.
- FlashDevelop is a free development environment and editor written in C # that allows you to create Flash applications using the Flash IDE, Flex SDK, MTASC or haxe.
- CodeDrive - A development environment and editor, with a fairly fast compiler, based on Microsoft Visual Studio.
- SWFTools - A free package for working with swf files, the package includes the ActionScript 3.0 compiler (as3compile).
Notes
- ↑ RFC 4329 (limit compatible with EcmaScript)
- ↑ Archived copy (inaccessible link) . Date of treatment July 9, 2015. Archived March 27, 2017.
- ↑ Ted Patrick | Entrepreneur, father, and interactive software developer Archived on September 30, 2009.
- ↑ Six reasons to use ActionScript 3.0 | Adobe Developer Connection