Opentopia Directory Encyclopedia Tools

ActionScript

Encyclopedia : A : AC : ACT : ActionScript


ActionScript is an ECMAScript-based programming language used for scripting Adobe Flash movies and applications. Since both ActionScript and JavaScript are based on the same ECMAScript syntax, fluency in one theoretically translates easily to the other. However, while JavaScript's DOM is browser window-, document- and form-centric, the ActionScript DOM is movie-centric, which may include animations, audio, text and event handling.

History

Creating ActionScript 2.0 in Adobe Flash MX Professional 2004 for Mac OS X 10.4. The code creates a simple bouncing ball that can be picked up and released.
Enlarge
Creating ActionScript 2.0 in Adobe Flash MX Professional 2004 for Mac OS X 10.4. The code creates a simple bouncing ball that can be picked up and released.

ActionScript first appeared in its current syntax with the release of Flash 5, which was the first thoroughly programmable version of Flash. This ActionScript release was named ActionScript 1.0. Flash 6 (MX) then further broadened the utility of the programming environment by adding a number of built-in functions and allowing better programmatic control of movie elements. Flash 7 (MX 2004) introduced ActionScript 2.0, which added strong typing and class-based programming features such as explicit class declarations, inheritance, interfaces, and Strict Data Typing. ActionScript 1.0 and 2.0 share the same compiled form within Flash SWFs (Small Web File).

Timeline

ActionScript 2.0 being made in an external editor, TextWrangler.
Enlarge
ActionScript 2.0 being made in an external editor, TextWrangler.

The Language

Syntax

In ActionScript 2.0 there can be classes, and also, a library item (a movie clip) can be associated with a class. Classes are always written in external text files, and these files must have the .as extension. Classes are extensions to the ActionScript language which the programmer can write him/herself, though there are many built-in classes such as the MovieClip class, which can be used to draw vectors onto the screen dynamically. Class files can be used to make your programming easier, and the class files can be transferred between many projects if needed.

Features of the Flash ActionScript implementation that JavaScript programmers may find interesting:

ActionScript code is frequently written directly in the Flash authoring environment, which offers reference, code hints and syntax highlighting. Often, the source code is saved along with the rest of the movie in a .fla file. It is also common for ActionScript code to be imported from external text files via #include statements. In this case, the external files may be compiled with the built-in compiler in the Flash IDE or with Motion Twin ActionScript2 Compiler (MTASC). See external links.

Criticism

Examples

ActionScript 2.0 Examples

Creating ActionScript 2.0 in Macromedia Flash MX Professional 2004 in Mac OS X 10.2. The code creates a customizable animation similar to the one seen during the boot process of Mac OS X.
Enlarge
Creating ActionScript 2.0 in Macromedia Flash MX Professional 2004 in Mac OS X 10.2. The code creates a customizable animation similar to the one seen during the boot process of Mac OS X.

The following prints Hello world. Note this will only work when run inside the Flash IDE, as the trace function is only supported inside it.

trace("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 () ;
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.
var my_Array:Array = new Array("Hello", "ActionScript", 3, 7, 11, "Flash");
Array.prototype.pickNumber = function():Number  ;
Array.prototype.pickString = function():String  ;
var num:Number = my_Array.pickNumber();
var str:String = my_Array.pickString();
_root.createTextField("txt", 1, 10, 10, 530, 390);
txt.text = "Array = "+my_Array+"\nRandom Number = "+num+"\nRandom String = "+str;
Array and dataProvider example:

var aData:Array = ;
dataProvider.dataGrid = aData;

ActionScript 3.0 Examples

This Hello World example uses ActionScript 3.0:

package 
}
}

External links

Technical

Tutorials

Resources

Other

See also

 


From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.

Search Titles
0123456789
ABCDEFGHIJ
KLMNOPQRST
UVWXYZ?

E-mail this article to:

Personal Message: