Adobe 65009333 - InCopy CS4 - PC Manual page 11

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

Advertisement

Getting Started
Value Type
Boolean
Integer
Number
String
Array
Converting values from one type to another
JavaScript provides ways to convert variable values from one type to another. Most commonly, numbers
are converted to strings (so you can enter them in text or display them in dialogs) or strings are converted
to numbers (so you can use them to set a point size or page location).
//To convert from a number to a string:
myNumber = 2;
myString = myNumber + "";
//To convert from a string to an integer:
myString = "2";
myNumber = parseInt(myString);
//If your string contains a decimal value, use "parseFloat" rather than "parseInt":
myNumber = parseFloat(myString);
//You can also convert strings to numbers using the following:
myNumber = +myString;
Variables
A variable is a container for a value. They are called "variables" because the values they contain might
change. A variable might hold a number, a string of text, or a reference to an InCopy object. Variables have
names, and you refer to a variable by its name. To put a value into a variable, you assign the data to the
variable.
In all examples and tutorial scripts that come with InCopy, all variables start with
easily differentiate variables we created in a script from scripting-language terms.
Assigning a value to a variable
Assigning values or strings to variables is fairly simple, as shown below:
var myNumber = 10;
var myString = "Hello, World!";
var myTextFrame = myDocument.pages.item(0).textFrames.add();
N
: In JavaScript, all variables not preceded by
OTE
bound to a specific function. While var is not required, we recommend you use it in any script with more
than one function.
What it is
Logical True or False
Whole numbers (no decimal
points). Integers can be positive or
negative.
A high-precision number that can
contain a decimal point.
A series of text characters. Strings
appear inside (straight) quotation
marks.
A list of values (the values can be
any type).
Scripting terminology and the InCopy object model 11
Example
True
14
13.9972
"I am a string"
["0p0", "0p0", "16p4", "20p6"]
are considered global by default; that is, they are not
var
. This enables you to
my

Advertisement

Table of Contents
loading

This manual is also suitable for:

Incopy cs4

Table of Contents