AllExperts > Encyclopedia 
Search      
Find out about volunteering to AllExperts

ActionScript: Encyclopedia BETA


Free Encyclopedia
 Home · Index · Browse A-Z  · Questions and Answers ·
Encyclopedia

Browse A-Z
ABCDEFGHIJKLMNOPQRSTUVWXYZNum


License
Disclaimer

 
 
 
 
Free Online Courses
12 Weeks to Weight Loss
Take Charge of Stress
Learn How to Bake
Budgeting 101
Deeper Faith
DIY Fashion Makeover

       MORE E-COURSES
 
   

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z  Misc

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

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 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 (Shock Wave File).

Timeline

ActionScript 2.0 being made in an external editor, TextWrangler.

* Flash Player 2: 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 true ActionScript. Used Prototype-based programming based on ECMAScript, and allowed full Procedural programming and Object-Oriented programming.
* Flash Player 6: Added an event handling model, and support for switch.
* Flash Player 7: Flash Player 7 offered some new features such as CSS text and performance improvements. Macromedia Flash compilers released alongside Flash Player 7 also support ActionScript 2.0, a Class programming language based on the ECMAScript 4 Netscape Proposal. However, ActionScript 2.0 can cross compile to ActionScript 1.0 byte-code, so it can be run by Flash Player 6.
* Flash Player 8: Further extended ActionScript 2.0 by adding new class libraries with APIs for controlling bitmap data at run-time, and file-upload.
* 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 compilation. This is the first release of the player to be titled Adobe Flash Player.
* Flash Lite: Flash Lite is the Flash technology specifically developed for mobile phones and consumer electronics devices.

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:
* Everything is designed to be asynchronous; callbacks are ubiquitous, but Event objects do not exist.
* The XML implementation has been present since Flash 5. Flash can send and receive XML, which can be used to create online multiplayer games via an online server.

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

*Programmers say the Macromedia ActionScript 2.0 compiler is rather slow, often taking several minutes to compile around 100 classes, though the open-source compiler MTASC can be used which compiles a lot faster.
*ActionScript's very tolerant syntax is often frowned upon by programmers, as it often makes it hard to read unclean code. However, long-time ActionScripters and JavaScripters find the version 2.0 class-based programming model and the introduction of strict datatypes far more difficult to work with than previous versions of the language.
*Flash's ActionScript VM tends to hit a ceiling quickly in regards to the amount of computation that ActionScript can perform before triggering an internal timeout, especially on the Mac Flash Player. Simply counting the numbers from 1 to 5000, for instance, threatens to exceed the capacity of the Flash Player for some users.
*Many people do not like having to import certain classes into Flash 8 before being able to use them; unfortunately for them, ActionScript 3.0 relies heavily on importing classes and scripting without is practically impossible.
*The .swf file format is easy to decompile making it very difficult to keep the source code secret.

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.

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 () {
trace("X: "+_root._xmouse);
trace("Y: "+_root._ymouse);
};

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 {
var rand:Number = random(this.length);
return (typeof (this[rand]) == "number") ? this[rand] : this.pickNumber();
};
Array.prototype.pickString = function():String {
var rand:Number = random(this.length);
return (typeof (this[rand]) == "string") ? this[rand] : this.pickString();
};
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 = [{name: "J. Bell", age: "55"}, {name: "B. Longman", age: "21"}];
 dataProvider.dataGrid = aData;

ActionScript 3.0 Examples

This Hello World example uses ActionScript 3.0:
 package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.filters.DropShadowFilter;
public class HelloWorld2 extends Sprite {
public function HelloWorld2() {
var shad:DropShadowFilter = new DropShadowFilter(2, 45, 0x000000, 25, 3, 3, 2, 2);
var txt:TextField = new TextField();
txt.textColor = 0xFFFFFF;
txt.filters = [shad];
txt.width = 120;
txt.x = Math.random()*300;
txt.y = Math.random()*300;
txt.selectable = false;
txt.text = "Hello World welcome! ["+Math.round(txt.x)+","+Math.round(txt.y)+"]";
addChild(txt);
}
}
}

External links

Technical

* Official (pre-release) ActionScript 3.0 Language Reference
* Macromedia Labs - Resource site for Macromedia technologies under development.
* Official ActionScript Coding Standards PDF
* CodeAlloy: ActionScript 2.0 FAQ - Information about changes in the second version.

Tutorials

* Macromedia Flash Support Center: Using ActionScript - Tutorials and articles directly from Macromedia.
* ActionScript.com - News, information and tutorials for Flash and Flex developers.
* ActionScript.org - Developer community and source of tutorials, code-snippets and movie-clips.
* Free Actionscript Video Tutorials - Great Resource
* Actionscript Hero - Flash MX 2004 and ActionScript 2.0 Tutorials.
* Kirupa.com: ActionScript Guide - Large number of tutorials covering many techniques.
* Flash Game Design - A step by step PDF guide to Flash game design.
* Programming with ActionScript - A step by step PDF guide to programming with ActionScript.
* Flashkit - A great resource of tutorials and downloadable examples.
* The Flash Game Programming Wiki - A Wiki about game programming and development with Flash/ActionScript.
* senocular as3 with mxmlc - A great tutorial about the use of actionscript 3, and a how to start.

Resources

* OSFlash - A resource site for open source Flash projects and tools.
* MTASC - An open source command line ActionScript 2.0 compiler written in OCaml.
* haXe - Another programming language that can be used to compiler SWF, by the authors of MTASC
* NeoSwiff A C# to SWF compiler
* KineticFusion - a commercial cross-platform ActionScript 2.0 compiler written in Java.
* secureSWF - a free ActionScript Obfuscator.
* SE|PY Actionscript Editor - An open source actionscript editor.
* FlashDevelop - FlashDevelop is a .NET open source script editor designed mostly for Actionscript 2 development. FlashDevelop is very quick to setup and easy to use as an external editor for the Flash IDE or as a complete open source development environment.
* V-Cam - A virtual "camera" written by Sham Bahngal.
* UltraShock - Actionscript2.0 tutorial by Dave Yang.
* GotoAndLearn - Video Learning Tutorials for Flash and ActionScript.

Other

* ActionScript Hero - Adobe Community Expert. Admin of Actionscript Hero Adventures.
* FlashGuru - FlashGuru's Reference blog for Flash Developers.
* Newgrounds - A community site where you can post your Flash games, there is also the Flash forum where you can seek help. AS main a list of actionscript tutorials on Newgrounds
* Gotoandplay: a bunch of flash examples: Flash applied
* Flashplayer - a site where one can post flash animations or games and view other's animations and games for free
* UnitZeroOne - A blog for Flash Developers.
* FlashKit - A Flash Developers Resourse Site including tutorials, sound fx and music.

See also

*ECMAScript
*Lingo for Macromedia Director
*Macromedia Flash
*Scripting
*Macromedia



Email this page
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy | Help
About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.
This is the "GNU Free Documentation License" reference article from the English Wikipedia. All text is available under the terms of the GNU Free Documentation License. See also our Disclaimer.