Object

Example 1: Store properties of an object

In this example, we will store the Return Values of the GetSelectionStyle function into a new variable named textStyle

Text_1.SetSelection(0,-1)
var textStyle = Text_1.GetSelectionStyle()

The first line of code selects all of the text in a Text object named Text_1. The second line shows a variable named textStyle which holds the object returned by the function GetSelectionStyle.

Example 2: Store property into a variable

The new object named textStyle (created in Example 1 above) has a number of properties. By adding this next line of code you can store one of the properties of an object into another variable. For example, to store the value of the property fontname (a property of the returned object for the GetSelectionStyle function), use the following syntax:

var OldStyle = textStyle.fontname
Debug.trace(OldStyle)

The OldStyle variable will contain a string showing the name of the font used for the Text object Text_1 e.g. "Arial". The second line of code shows the value of OldStyle in a Debug window. In practice, you won’t want to show the variable in a Debug window, you are more likely to want to use other functions to interrogate the data. For example, you may want to check if the font used is Arial – if it isn’t Arial you can change the font to Arial (see Example 3 and 4 below).

Example 3: Create your own object

Often you may want to create your own object – this is normally when you want to change the data returned in an object when you have used a Get function. First lets look at how you create a new object and add properties to the object

var SpaceShip = new Object()
SpaceShip.Height = 50
SpaceShip.Width = 30

The first line of code creates a new object. The syntax is always the same whenever you create a new object, that is

VariableName = new Object()

The VariableName will change for each new object (in Example 3 the variable name is SpaceShip) but everything after the equal sign remains the same. The second and third lines in Example 3 create two new properties for the object, Height and Width which are given a value.

Example 4: Using a new object with other functions

Often, you will only want to create your own object if you want to change the data in an object on a page while the publication is running. For example:

myText.SetSelection(0,-1)
var newStyle = new Object()
newStyle.bold = true
newStyle.fontname = "Comic Sans MS"
myText.SetSelectionStyle(newStyle)

The first line of code selects all of the text in a Text object named myText. The middle lines of code create a new object named newStyle and set two properties bold and fontname. In the last line of code, the properties in the object newStyle are applied to the Text object myText.

Close