Conditional Statements - Adobe 65009333 - InCopy CS4 - PC Manual

Scripting guide: javascript
Hide thumbs Also See for 65009333 - InCopy CS4 - PC:
Table of Contents

Advertisement

Getting Started
Scripting terminology and the InCopy object model 12
Try to use descriptive names for your variables, like
or
, rather than
or
. This
firstPage
corporateLogo
x
c
makes your script easier to read. Longer names do not affect the execution speed of the script.
Variable names must be one word, but you can use internal capitalization (like
) or
myFirstPage
underscore characters (
) to create more readable names. Variable names cannot begin
my_first_page
with a number, and they cannot contain punctuation or quotation marks.
Array variables
An Array object is a container for a series of values:
myArray = [1, 2, 3, 4];
To refer to an item in an array, refer to its index in the array.In JavaScript, the first item in an array is item 0:
var myFirstArrayItem = myArray[0];
Arrays can include other arrays, as shown in the following examples:
var myArray = [[0,0], [72,72]];
Finding the value type of a variable
Sometimes, your scripts must make decisions based on the value type of an object. If you are working on a
script that operates on a text selection, for example, you might want that script to stop if nothing is
selected.
//Given a variable of unknown type, "myMysteryVariable"...
myType = myMysteryVariable.constructor.name;
//myType will be a string corresponding to the JavaScript type (e.g., "Rectangle")
Operators
Operators use variables or values to perform calculations (addition, subtraction, multiplication, and
division) and return a value. For example:
MyWidth/2
returns a value equal to half of the content of the variable
.
myWidth
You also can use operators to perform comparisons (equal to (
), not equal to(
), greater than (
), or less
=
<>
>
than (
)). For example:
<
MyWidth > myHeight
returns the value
(or 1) if
is greater than
; otherwise,
(0).
true
myWidth
myHeight
false
In JavaScript, use the plus sign (
) to join the two strings:
+
"Pride " + "and Prejudice"
//returns the string: "Pride and Prejudice"

Conditional statements

"If the size of the selected text is 12 points, set the point size to 10 points. " This is an example of a
conditional statement. Conditional statements make decisions; they give your scripts a way to evaluate
something (like the color of the selected text, number of pages in the document, or date), then act
according to the result. Most conditional statements start with
.
if

Advertisement

Table of Contents
loading

This manual is also suitable for:

Incopy cs4

Table of Contents