44
Chapter 2: Director Scripting Essentials
To create a copy of a list that is independent of another list:
•
Use the
duplicate()
method.
For example, the following statements create a list and then make an independent copy of the list.
-- Lingo syntax
oldList = ["a", "b", "c"]
newList = oldList.duplicate() -- makes an independent copy of oldList
// JavaScript syntax
var oldList = list("a", "b", "c");
var newList = oldList.duplicate(); // makes an independent copy of oldList
After
newList
is created, editing either
oldList
or
newList
has no effect on the other.
Sorting lists
Lists are sorted in alphanumeric order, with numbers being sorted before strings. Strings are
sorted according to their initial letters, regardless of how many characters they contain. Sorted
lists perform slightly faster than unsorted lists.
A linear list is sorted according to the values in the list. A property list is sorted according to the
property names in the list or array.
After the values in a linear or property list are sorted, they will remain sorted, even as values are
added to or removed from the lists.
To sort a list:
•
Use the
sort()
method.
For example, the following statements sort a nonsorted alphabetical list.
-- Lingo syntax
oldList = ["d", "a", "c", "b"]
oldList.sort() -- results in ["a", "b", "c", "d"]
// JavaScript syntax
var oldList = list("d", "a", "c", "b");
oldList.sort(); // results in ["a", "b", "c", "d"]
Creating multidimensional lists
You can also create multidimensional lists that enable you to work with the values of more than
one list at a time.
In the following example, the first two statements create the separate linear lists
list1
and
list2
.
The third statement creates a multidimensional list and assigns it to
mdList
. To access the values
in a multidimensional list, the fourth and fifth statements use brackets to access the values in the
list; the first bracket provides access to a specified list, and the second bracket provides access to
the value at a specified index position in the list.
-- Lingo syntax
list1 = list(5,10)
list2 = list(15,20)
mdList = list(list1, list2)
trace(mdList[1][2]) -- displays 10
trace(mdList[2][1]) -- displays 15
Содержание DIRECTOR MX 2004
Страница 1: ...DIRECTOR MX 2004 Director Scripting Reference...
Страница 48: ...48 Chapter 2 Director Scripting Essentials...
Страница 100: ...100 Chapter 4 Debugging Scripts in Director...
Страница 118: ...118 Chapter 5 Director Core Objects...
Страница 594: ...594 Chapter 12 Methods...
Страница 684: ...684 Chapter 14 Properties See also DVD...
Страница 702: ...702 Chapter 14 Properties See also face vertices vertices flat...
Страница 856: ...856 Chapter 14 Properties JavaScript syntax sprite 15 member member 3 4...
Страница 889: ...netPresent 889 _player alert Sorry the Network Support Xtras could not be found See also Player...
Страница 1102: ...1102 Chapter 14 Properties...