ActionScript
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).
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 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);
}
}
}
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: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"/>
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 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 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. Objects in their basic form can be used as associative arrays that contain key-value pairs, where keys are Strings and values may be any type.
** Array - Contains a list of data. Though ActionScript 3 is a strongly typed language, the contents of an Array may be of any type and values must be cast back to their original type after retrieval. (Support for typed Arrays has recently been added with the Vector class.)
** Vector - A variant on Array supported only when publishing for Flash Player 10 or above. Vectors are typed, dense Arrays (values must be defined or null) which may be fixed-length, and are bounds-checked during retrieval. Vectors are not just more typesafe than Arrays but also perform faster.
** Dictionary** - Dictionaries are a variant of Object that may contain keys of any data type (whereas Object always uses strings for its keys).
** 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 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.
Closed until further notice
Well, it's been a fun ride, but we've had to close our doors officially. We'll leave the games up so you can keep playing if you so desire, but everything else is shut down. It's been fun!
