Javascript Syntax Arrays - MACROMEDIA DIRECTOR MX 2004-DIRECTOR SCRIPTING Reference

Director scripting reference
Table of Contents

Advertisement

// JavaScript syntax
var list1 = list(5,10);
var list2 = list(15,20);
var mdList = list(list1, list2);
trace(mdList[1][2]); // displays 10
trace(mdList[2][1]); // displays 15

JavaScript syntax arrays

JavaScript syntax arrays are similar to Lingo-style linear lists in that each element in an array is a
single value. One of the main differences between JavaScript syntax arrays and Lingo-style linear
lists is that the index into an array always starts with 0.
You create a JavaScript syntax array by using the Array object. You can use either square brackets
(
) or the
[ ]
Array
with two values.
// JavaScript syntax
var myArray = [10, 15]; // using square brackets
var myArray = new Array(10, 15); // using the Array constructor
You can also create empty arrays. The following two statements create an empty array.
// JavaScript syntax
var myArray = [];
var myArray = new Array();
Note: The Director Scripting Reference does not include a complete reference for JavaScript syntax
Array objects. For more complete information on using Array objects, see one of the many third-party
resources on the subject.
Checking items in arrays
You can determine the characteristics of an array and the number of items the array contains by
using the following methods.
To display the contents of a list, use the
contains the list as a parameter.
To determine the number of items in an array, use the Array object's
To determine an array's type, use the
The following example illustrates determining the number of items in an array using the
property, and then returning the type of object using the
length
// JavaScript syntax
var x = ["1", "2", "3"];
trace(x.length) // displays 3
trace(x.contructor == Array) // displays true
Adding and deleting items in arrays
You can add or delete items in an array by using the following methods:
To add an item at the end of an array, use the Array object's
To add an item at its proper position in a sorted array, use the Array object's
To add an item at a specific position in an array, use the Array object's
constructor to create an array. The following two statements create an array
constructor
or
function, passing the variable that
put()
trace()
property.
push()
property.
length
property.
constructor
method.
method.
splice()
method.
splice()
JavaScript syntax arrays
45

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Director mx 2004

Table of Contents