Adding and deleting items in lists
You can add or delete items in a list by using the following methods.
•
To add an item at the end of a list, use the
•
To add an item at its proper position in a sorted list, use the
•
To add an item at a specific place in a linear list, use the
•
To add an item at a specific position in a property list, use the
•
To delete an item from a list, use the
•
To replace an item in a list, use the
The following statements use
-- Lingo syntax
workerList = ["Bruno", "Heather", "Carlos"] -- define a linear list
workerList.append("David")
trace(workerList) -- displays ["Bruno", "Heather", "Carlos", "David"]
// JavaScript syntax
var workerList = list("Bruno", "Heather", "Carlos"); // define a linear list
workerList.append("David");
trace(workerList); // displays ["Bruno", "Heather", "Carlos", "David"]
The following statements use
property list.
-- Lingo syntax
-- define a property list
foodList = [#breakfast:"Waffles", #lunch:"Tofu Burger"]
foodList.addProp(#dinner, "Spaghetti") -- adds [#dinner: "Spaghetti"]
// JavaScript syntax
// define a property list
var foodList = propList("breakfast", "Waffles", "lunch", "Tofu Burger");
foodList.addProp("dinner", "Spaghetti"); // adds ["dinner": "Spaghetti"]
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
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 first statement below creates a list that contains the
names of two continents, and assigns the list to the variable
assigns the same list to a new variable
to
also automatically adds
landList
because both variable names point to the same list object in memory. The same behavior occurs
by using an array in JavaScript syntax.
-- Lingo syntax
landList = ["Asia", "Africa"]
continentList = landList
landList.add("Australia") -- this also adds "Australia" to continentList
append()
deleteAt()
or
setAt()
setaProp()
to add an item to the end of a list.
append()
to add a property and an associated value to a
addProp()
(Lingo) or
VOID
null
continentList
to the list
Australia
method.
or
add()
addProp()
method.
addAt()
addProp()
,
, or
deleteOne()
deleteProp
methods.
(JavaScript syntax).
. The second statement
landList
. In the third statement, adding
continentList
Linear lists and property lists
methods.
method.
() methods.
Australia
. This happens
43
Need help?
Do you have a question about the DIRECTOR MX 2004-DIRECTOR SCRIPTING and is the answer not in the manual?
Questions and answers