Variables is actionscript are extrodianarily useful, especially if you need to do anything slighly complex, they allow you to copy information easily from one function to another, or,even many, they allow you to pass information to and, from a database or another external source basically without them creating interesting interactive flash would become impossible.

There are a couple of different types of variables in actionscript 3, which should be predefined when writing scripts, to prevent errors caused by the input of incorrect data/datatype.

 The main three are:

  • String
  • Number
  • Boolean 

A String can be contain any information, text or numbers, and is generally used for moving blocks of text around, a Number is exactly as it sounds... a number, and, Boolean is argument of either true or false.

When working with variables, you need to make sure that you define them in the code, before you start calling them in a function, otherwise the fuction will not work, this is done like:

var variable1:String="ABC";
var variable2:Boolean=true;
var variable3:Number=12
var variable4:Array=["a","b","c"];

 or

function setText() {
var newText:String = "Hello World";
   myDynamicTextBox.text = newText;
}

 As long as the variable is defined before it is being called for use, you should not have any issues. 

 

The full list of Variable/Data types, are included below:

ActionScript 3 top level data types 

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

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