ActionScript

ActionScript

Infobox programming language
name = ActionScript

paradigm = Multi-paradigm
year = 1998
designer = Gary Grossman
developer = Macromedia (now Adobe Systems)
latest_release_version = 3.0
latest_release_date = June 27, 2006
typing = strong, static, safeFact|date=April 2008
implementations = Adobe Flash, Adobe Flex
operating_system = Cross-platform
influenced_by = JavaScript, Java

infobox file format
name = ActionScript
extension = .as
mime = application/actionscript [RFC 4329]

ActionScript is a scripting language based on ECMAScript. ActionScript is used primarily for the development of websites and software using the Adobe Flash Player platform (in the form of SWF files embedded into Web pages), but is also used in some database applications (such as Alpha Five). Originally developed by Macromedia, the language is now owned by Adobe (which acquired Macromedia in 2005). ActionScript was initially designed for controlling simple 2D vector animations made in Adobe Flash (formerly Macromedia Flash). Later versions added functionality allowing for the creation of Web-based games and rich Internet applications with streaming media (such as video and audio).

History

ActionScript started as a scripting language for Macromedia's Shockwave Flash authoring tool, now developed by Adobe 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 .

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 SWFs (loadMovie).

* Flash Player 4: First player with a full scripting implementation (called "Actions"). The scripting was a slash 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 based on [http://www.ecma-international.org/publications/standards/Ecma-262.htm ECMAScript] , and allowed full procedural programming and object-oriented programming.

* Flash Player 6: Added an event handling model, accessibility controls and support for switch. The first version with support for the AMF and RTMP 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 [http://www.ecmascript.org/ ECMAScript 4 Netscape Proposal] with class-based inheritance. 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 XML parsing, full-screen mode and Regular Expressions were added. This is the first release of the player to be titled [http://www.adobe.com/products/flashplayer Adobe Flash Player] .

* Flash Player 10 currently beta (initially called Astro): Added basic 3D 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. Graphic processing is now offloaded to the GPU which gives a noticeable increase to rendering time for each frame, basically higher Frame rate. There is a new sound API which allows for custom creation of audio in flash, something that has never been possible before. [http://labs.adobe.com/technologies/flashplayer10/]

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. [Note that the name "ActionScript 1.0" is a retronym, coined after the release of ActionScript 2.0.] 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.

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

2006–today: 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 is faster than its previous versions but still not fast enough for fullscreen applications with many objects active. Actionscript 3.0 has limited support for hardware acceleration ( DirectX, 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, namespaces, and regular expressions.
* Compiles to an entirely new type of bytecode, incompatible with ActionScript 1.0 and 2.0 bytecode.
* Revised Flash Player API, organized into packages.
* Unified event handling system based on the DOM event handling standard.
* Integration of ECMAScript for XML (E4X) for purposes of XML processing.
* Direct access to the Flash runtime display list for complete control of what gets displayed at runtime.
* Completely conforming implementation of the ECMAScript 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 video playback.

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() {} 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 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); } Finally, an example of using ActionScript when developing Flex 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 application file:

Examples

ActionScript 2.0 examples

The following code prints Hello world to the stage (screen). this.createTextField("myText", 1, 0, 0, 100, 25);this.myText.text = "Hello world!";

The following code outputs the current mouse position when the mouse moves, by using the onMouseMove event. Again this will only work in the Flash IDE.onMouseMove = function (){ trace("X: " + this._xmouse); trace("Y: " + this._ymouse);};

The following code, when placed on a Button, begins to play the timeline of the MovieClip the button is placed in. This also applies to the root timeline since the root is considered a MovieClip as well. (Note: This method of coding is deprecated and should no longer be used)on(release){ play();}

This more advanced example creates an array containing numbers and strings, and assigns a number to a variable called num and a string to a variable called str using prototype functions and function recursion. Then, using the MovieClip API, a text field is drawn on screen, into which the variable values are written.Array.prototype.pickNumber = function():Number{ var rand:Number = Math.floor(Math.random() * this.length); return (typeof (this [rand] ) = "number") ? this [rand] : this.pickNumber();};

Array.prototype.pickString = function():String{ var rand:Number = Math.floor(Math.random() * this.length); return (typeof (this [rand] ) = "string") ? this [rand] : this.pickString();};

var myArray:Array = new Array("Hello", "ActionScript", 3, 7, 11, "Flash");var num:Number = myArray.pickNumber();var str:String = myArray.pickString();this.createTextField("txt", 1, 10, 10, 530, 390);txt.text = "Array = " + myArray + " Random Number = " + num + " Random String = " + str;

Array and dataProvider example:var aData:Array = [{name: "J. Bell", age: "55"}, {name: "B. Longman", age: "21"}] ;dataGrid.dataProvider = aData;

ActionScript 3.0 examples

This Hello World example uses ActionScript 3.0:package { import flash.display.Sprite; import flash.text.TextField;

public class HelloWorld extends Sprite {

public function HelloWorld() { var txt:TextField = new TextField(); txt.text = "Hello World!"; addChild(txt); }

Data structures

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 top level data types(see [http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000047.html 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 complex data types(see [http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000047.html 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.
* Array - Contains a list of data. Though ActionScript 3 is a strongly-typed language, it does not support typed Arrays. Thus the contents of an Array may be of any type.
* MovieClip - Animated movie clip display object; a descendant (with minor modifications) of the main Flash timeline.
* Bitmap - A non-animated bitmap display object.
* Shape - A non-animated vector shape object.
* ByteArray - Contains an array of binary byte data.
* TextField - A dynamic, optionally interactive text field object.
* SimpleButton - A simple interactive button type supporting "up","over", and "down" states with an arbitrary hit area.
* Date - A date object containing the current system date/time.
* 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.
* Video - A video playback object supporting direct (progressive download) or streaming (RTMP) transports. As of Flash Player version 9.0.115.0, the open 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 E4C standard; 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 types and reference types. In ActionScript, all variables are reference types. [http://livedocs.adobe.com/flex/3/html/03_Language_and_Syntax_19.html]

Some data types can be assigned values with literals:var item1:String="ABC";var item2:Boolean=true;var item3:Number=12var item4:Array= ["a","b","c"] ;var item5:XML = ; //Note that the primitive XML is not quotedA 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://Removal of 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 object is using the orphaned object), it is removed from memory. Only references may be removed by using the "delete" keyword. For this reason, memory management in ActionScript is tricky and 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

Footnotes

See also

*ECMAScript — The standardized scripting language upon which ActionScript is based.
*Adobe Flash — The program in which ActionScript debuted.
*Adobe Flash Player — 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 - SDK and IDE which uses ActionScript
*SWF File Format
*Tamarin (JIT)
*Macromedia
*Adobe Systems
*Gnash, a free Flash viewer
*Swfdec
*Adobe Flex Builder - IDE by Adobe to author ActionScript

External links

Adobe documentation and references

* [http://www.adobe.com/devnet/actionscript/ ActionScript Technology Center]
* [http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/js/html/wwhelp.htm?href=Part4_ASLR2.html ActionScript 2.0 Language Reference]
* [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/ ActionScript 3.0 Language & Component Reference]
* [http://www.adobe.com/go/programmingAS3 Flex 3 LiveDocs: Programming ActionScript 3.0]

Tutorials / Resource Sites

* [http://www.gotoAndLearn.com] - Video Tutorials from Lee Brimelow
* [http://www.adobe.com/devnet/flash/] - Adobe - Flash Developer Center
* [http://www.flashkit.com] - Flashkit.com - Community Resource / Tutorials
* [http://www.kirupa.com/developer/flash/index.htm] - Kirupa.com - Community Resource / Tutorials
* [http://www.actionscript.org] - Actionscript.org - Community Resource / Tutorials

Tools and scripts

* [http://www.flashdevelop.org FlashDevelop] - Popular open-source ActionScript IDE
* Adobe
** [http://www.adobe.com/downloads/ Adobe Flash CS3] (ie. the Flash IDE)
** [http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+3 Adobe Flex SDK] (ie. the free SDK)
* [http://haxe.org/ haxe.org] - The HaXe compiler, the AS 3 successor to MTASC
* [http://www.mtasc.org/ Motion Twin ActionScript Compiler] - MTASC is an Open-source ActionScript 2 compiler
* [http://www.actionscriptcheatsheet.com/blog/ ActionScript Cheatsheet] - Free, printable quick reference cards for ActionScript 1.0, ActionScript 2.0, ActionScript 3.0, Papervision 3D and Adobe AIR.


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • ActionScript — Apparu en 1998 Auteur Gary Grossman Développeur Macromedia (maintenant Adobe Systems) Derni …   Wikipédia en Français

  • Actionscript — est le langage de programmation utilisé au sein d applications clientes (Adobe Flash, Adobe Flex) et serveur (Flash media server, JRun, Macromedia Generator). ActionScript est un langage de script, orienté objet et prototype, basé sur ECMAScript… …   Wikipédia en Français

  • ActionScript — Класс языка: Объектно ориентированный, Императивный, скриптовый Появился в: 1998 Автор(ы): Гари Гроссман …   Википедия

  • ActionScript — Basisdaten Paradigmen: objektorientiert Designer: Gary Grossman Entwickler …   Deutsch Wikipedia

  • Actionscript — (kurz: AS) ist eine Programmiersprache des US amerikanischen Softwareunternehmens Adobe Systems auf Basis des ECMAScript Standards (ECMA 262) und kann in einer Reihe von Adobe Produkten eingesetzt werden, so zum Beispiel Adobe Flash, Flex und Air …   Deutsch Wikipedia

  • ActionScript 3 — Saltar a navegación, búsqueda ActionScript Obtenido de ActionScript 3 …   Wikipedia Español

  • ActionScript — Объектно ориентированный язык программирования, один из диалектов ECMAScript, который добавляет интерактивность, обработку данных и многое другое в содержимое Flash приложений. ActionScript исполняется виртуальной машиной (ActionScript Virtual… …   Словарь бизнес-терминов

  • ActionScript — es un lenguaje de programación orientado a objetos (OOP), utilizado en especial en aplicaciones web animadas realizadas en el entorno Macromedia Flash, la tecnología de Macromedia para añadir dinamismo al panorama web. Fue lanzado con la versión… …   Enciclopedia Universal

  • ActionScript — Adobe ActionScript es el lenguaje de programación de la Plataforma Adobe Flash. Originalmente desarrollado como una forma para que los desarrolladores programen de forma más interactiva. La programación con ActionScript permite mucha más… …   Wikipedia Español

  • ActionScript Foundry — Développeur ServeBox Dernière version …   Wikipédia en Français

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”