| advertise add site services publishers database health videos | ![]() | about toolbar stats live show health store more stuff JOIN/LOGIN |
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), and in basic robotics, as with the Make Controller Kit. 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).
[edit] HistoryActionScript started as a scripting language for Macromedia's Flash authoring tool, now developed by Adobe Systems 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 . [edit] Timeline by player
[edit] Timeline by ActionScript version2000–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.[3] 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 structured 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 added limited support for hardware acceleration (DirectX, OpenGL). The update to the language introduced several new features:
[edit] Flash Lite
[edit] SyntaxActionScript 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. [edit] ActionScript 2.0The 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 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"; } } [edit] ActionScript 3.0ActionScript 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) 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: <?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> [edit] Data structures[edit] Data typesActionScript 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
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:
ActionScript 3 primitive (prime) data types (see Data type descriptions)
ActionScript 3 some complex data types (see Data type descriptions)
[edit] Using data typesThe 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. 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. [4] 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: var item1:String="ABC"; var item2:Boolean=true; var item3:Number=12; var item4:Array=["a","b","c"]; var item5:XML = <node><child/></node>; //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("<node><child/></node>"); 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: //<node><child value="13"/></node> 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("<node><child/></node>"); 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 [edit] See also
[edit] References
[edit] External links
[edit] Adobe documentation and references
[edit] Tutorials and references
[edit] Developer tools
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ↑ top of page ↑ | about thumbshots |