Writing Scripts with Lingo
401
Adding and deleting items in a list
You can add or delete items in a list by using the following commands. See entries for individual
commands in the Lingo Dictionary.
•
To add an item at the end of a list, use the
append
command.
•
To add an item at its proper position in a sorted list, use the
add
or
addProp
command.
•
To add an item at a specific place in a linear list, use the
addAt
command.
•
To add an item at a specific position in a property list, use the
addProp
command.
•
To delete an item from a list, use the
deleteAt
,
deleteOne
, or
deleteProp
command.
•
To replace an item in a list, use the
setAt
or
setaProp
command.
You do not have to explicitly remove lists. Lists are automatically removed when they are no
longer referred to by any variable. Other types of objects must be removed explicitly, by setting
variables that refer to them to
VOID
.
Copying lists
Assigning a list to a variable and then assigning that variable to a second variable does not make a
separate copy of the list. For example, the statement
landList = ["Asia", "Africa"]
creates a
list that contains the names of two continents. The statement
continentList = landList
assigns the same list to the variable
continentList
. However, adding Australia to
landList
using the statement
add landList, "Australia"
automatically adds Australia to
continentList
also. This happens because both variable names point to the same object
in memory.
To create a copy of a list that is independent of the first list:
•
Use the
duplicate()
function. See
duplicate() (list function)
in the Lingo Dictionary.
For example, this statement creates a list and assigns it to the variable
oldList
:
oldList = ["a", "b", "c"]
This statement uses the
duplicate()
function to make an independent copy of the list and
assign it to the variable
newList
:
newList = duplicate(oldList)
After
newList
is created, editing either
oldList
or
newList
has no effect on the other.
Sorting lists
Lists can be unsorted. However, Lingo can sort a list in alphanumeric order, with numbers 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.
Lingo sorts a linear list according to the values in the list. Lingo sorts a property list according to
the properties in the list.
To sort a list:
•
Use the
sort
command followed by the list’s name. See
sort
in the Lingo Dictionary.
Содержание DIRECTOR MX-USING DIRECTOR MX
Страница 1: ...Using Director MX Macromedia Director MX...
Страница 12: ...Contents 12...
Страница 156: ...Chapter 4 156...
Страница 202: ...Chapter 6 202...
Страница 244: ...Chapter 7 244...
Страница 292: ...Chapter 10 292...
Страница 330: ...Chapter 12 330...
Страница 356: ...Chapter 13 356...
Страница 372: ...Chapter 14 372...
Страница 442: ...Chapter 16 442...
Страница 472: ...Chapter 18 472...
Страница 520: ...Chapter 19 520...
Страница 536: ...Chapter 20 536...
Страница 562: ...Chapter 23 562...
Страница 566: ...Chapter 24 566...
Страница 602: ...Chapter 27 602...