ECMAScript data types

The educational technology and digital learning wiki
(Redirected from AS3 Variable Types)
Jump to navigation Jump to search


For now, this is a simple outline to keep track of the concepts that are assumed to have been described.


For now we describe the data types you need to write basic programs.

Primitive Data Types

Boolean, int, Null, Number, String, uint, and void.


Number. Data type representing any sort of number. int. Integer. Data type representing a number with no decimal part. uint. Unsigned integer. Data type representing a non negative integer


A variable of string data types represent a sequence of characters.


Variables defined as of boolean type can hold only two values: true or false. No other values are valid. When a boolean variable is declared without being given an initial value, its value is false.


The Null data type contains only one value, null


The void data type contains only one value, undefined.

Complex data types in ActionScript core classes

The full list of ActionScript 3 datatypes include: Object, Array, Date, Error, Function, RegExp, XML, and XMLList.


To create an array and to add some values, you can use something like:

var mylist = Array ();
mylist[]=2; mylist[]=3;


var mylist = [1,2,3];

Default numbering of elements starts at zero.

mylist[0]; // will return 1, i.e. the first element.

You can define the length of an array:

var mylist = new Array(12);

But it then can be increased later, e.g. this is ok:

mylist(14) = "bla";

There are several sorts of arrays:

  • normal arrays (as seen above)
var xx = [1,2,3];

But then we also can have:

  • typed arrays (ECMAScript 4 / JavaScript 2 - not tested !)
var xx = [ int] (12); // an array of 13 integer elements
var xx = [1,2,3] : [int]; // an array filled with 2 int. elements
var xx = new [int] (1,2,3); // same
  • associative arrays (records)
var hash = { x:10, y:"foo" }
This will return 10:
alert(hash ['x']);
  • typed associative arrays (ECMAScript 4 / JavaScript 2 - not tested !)
var hash = new { x:int, y:string }( 3, "foo" )
var hash = { x:10, y:"foo" } : { x:int, y:string }


Objects are an unordered collection of properties each of which contains a primitive value, object, or function. A function stored in a property of an object is called a method.

Internally speaking, objects are a kind of associative arrays or whatever they are called (e.g. records or hash structures). In fact, arrays are a special case of objects, i.e. an array is defined by the global JS object Array.prototype

Anyhow, the following should be internally the same or mostly (?) the same.

var take1 = {'prop1':0, 'prop2':1, 'prop2':2};

var take2 = new Object();
take2['prop1'] = 0;
take2['prop2'] = 1;
take2['prop3'] = 2;

var take3 = new Object();
take3.prop1 = 0;
take3.prop2 = 1;
take3.prop3 = 2;


Manuals and specifications

Flash 9/ActionScript 3
JavaScript 1.5

JavaScript Tutorials