User Guide

50 Chapter 3: Writing Scripts in Director
Therefore, after you know how to access the scripting APIs in one language, you essentially know
how to access them in the other language. For example, JavaScript syntax code can access Lingo
data types such as symbols, linear lists, property lists, and so on, create and invoke Lingo parent
scripts and behaviors, create and invoke Xtra extensions, and use Lingo string chunk expressions.
Also, both JavaScript syntax and Lingo scripts can be used within a single movie; however, a single
script cast member can contain only one syntax or the other.
There are two main differences between Lingo and JavaScript syntax:
Each language contains some terminology and syntax conventions that are unique to each
language. For example, the syntax for an event handler is different in Lingo than it is in
JavaScript syntax:
-- Lingo syntax
on mouseDown
...
end
// JavaScript syntax
function mouseDown() {
...
}
For more information on the terminology and syntax conventions used for each language, see
“Scripting terminology” on page 10 and “Scripting syntax” on page 12.
Some of the scripting APIs are accessed slightly differently in each language. For example,
you would use different constructs to access the second word in the first paragraph of a text
cast member:
-- Lingo syntax
member("News Items").paragraph[1].word[2]
// JavaScript syntax
member("News Items").getPropRef("paragraph", 1).getProp("word", 2);
Scripting in dot syntax format
Whether you write scripts in Lingo or JavaScript syntax, you write them by using the dot syntax
format. You use dot syntax to access the properties or methods related to an object. A dot syntax
statement begins with a reference to an object, followed by a period (dot), and then the name of
the property, method, or text chunk that you want to specify. Each dot in a statement essentially
represents a move from a higher, more general level in the object hierarchy to a lower, more
specific level in the object hierarchy.
For example, the following statement first creates a reference to the cast library named "News
Stories", and then uses dot syntax to access the number of cast members in that cast library.
-- Lingo syntax
castLib("News Stories").member.count
// JavaScript syntax
castLib("News Stories").member.count;