86
Chapter 4: Debugging Scripts in Director
Looking for syntax errors
Syntax errors are probably the most common bug encountered while scripting. When a script
fails, it is a good idea to first make sure that:
•
Terms are spelled correctly, spaces are in the correct places, and necessary punctuation is used.
Director cannot interpret incorrect syntax.
•
Quotation marks surround the names of cast members, labels, and strings within a statement.
•
All necessary parameters are present. The specific parameters depend on the individual
element. See the API topic entries in this reference to determine any additional parameters that
an element requires.
Looking for other simple bugs
If your script compiles without an error message, it might contain a bug. If your script is not
doing what you want, check the following:
•
Values for parameters are correct. For example, using an incorrect value for the number of
beeps that you want the
beep()
method to generate gives you the wrong number of beeps.
•
Values that change—such as variables and the content of text cast members—have the values
you want. You can display their values in the Object inspector by selecting the name of the
object and clicking Inspect Object in the Script window, or in the Message window by using
the
put()
or
trace()
functions.
•
The scripting elements do what you think they do. You can check their behavior by referring to
the API topic entries in this reference.
•
If the script is written in JavaScript syntax, the script may contain a capitalization error.
JavaScript syntax is case-sensitive, which means that all methods, functions, properties, and
variables must be referred to by using the correct capitalization.
If you attempt to call a method or function by using incorrect capitalization, you will receive a
script error.
If you attempt to access a variable or property by using incorrect capitalization, you may not
receive a script error, but your script may not behave as expected. For example, the following
mouseUp
handler contains a statement that attempts to access the
itemLabel
property by using
incorrect capitalization. This script does not produce a script error, but instead dynamically
creates a new variable with the incorrect capitalization. The value of the newly created variable
is
undefined
.
// JavaScript syntax
function beginSprite() {
this.itemLabel = "Blue prints";
}
function mouseUp() {
trace(this.itemlabel) // creates the itemlabel property
}
Содержание DIRECTOR MX 2004-DIRECTOR SCRIPTING
Страница 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...