Adobe 0046100128056 - InDesign - Mac Manual page 157

Javascript
Table of Contents

Advertisement

C
11: Creating Dynamic Documents
Creating Multistate Objects 157
HAPTER
//Given a document "myDocument" and a page "myPage" and
//four colors "myColorA," "myColorB," "myColorC," and "myColorD"...
var myMSO = myPage.multiStateObjects.add({name:"Spinner", geometricBounds:[72, 72,
144, 144]});
//New multistate objects contain two states when they're created. Add two more.
myMSO.states.item(0).name = "Up";
myMSO.states.item(1).name = "Right";
//Add two more states.
myMSO.states.add({name:"Down"});
myMSO.states.add({name:"Left"});
//Add page items to the states.
var myPolygon = myMSO.states.item(0).polygons.add({fillColor:myColorA,
strokeColor:myDocument.swatches.item("None")});
myPolygon.paths.item(0).entirePath = [[72, 144], [144, 144], [108, 72]];
myPolygon = myMSO.states.item(1).polygons.add({fillColor:myColorB,
strokeColor:myDocument.swatches.item("None")});
myPolygon.paths.item(0).entirePath = [[72, 72], [72, 144], [144, 108]];
myPolygon = myMSO.states.item(2).polygons.add({fillColor:myColorC,
strokeColor:myDocument.swatches.item("None")});
myPolygon.paths.item(0).entirePath = [[72, 72], [108, 144], [144, 72]];
myPolygon = myMSO.states.item(3).polygons.add({fillColor:myColorD,
strokeColor:myDocument.swatches.item("None")});
myPolygon.paths.item(0).entirePath = [[144, 72], [72, 108], [144, 144]];
Typically, you'll control the display of the states in a multistate object using a button. The following script
fragment shows how to do this (for the complete script, refer to MultiStateObjectControl).
//Given a document "myDocument" and a page "myPage" and
//four colors "myColorA," "myColorB," "myColorC," and "myColorD"...
var myMSO = myPage.multiStateObjects.add({name:"Spinner", geometricBounds:[72, 72,
144, 144]});
//New multistate objects contain two states when they're created. Add two more.
myMSO.states.item(0).name = "Up";
myMSO.states.item(1).name = "Right";
//Add two more states.
myMSO.states.add({name:"Down"});
myMSO.states.add({name:"Left"});
//Add page items to the states.
var myPolygon = myMSO.states.item(0).polygons.add({fillColor:myColorA,
strokeColor:myDocument.swatches.item("None")});
myPolygon.paths.item(0).entirePath = [[72, 144], [144, 144], [108, 72]];
myPolygon = myMSO.states.item(1).polygons.add({fillColor:myColorB,
strokeColor:myDocument.swatches.item("None")});
myPolygon.paths.item(0).entirePath = [[72, 72], [72, 144], [144, 108]];
myPolygon = myMSO.states.item(2).polygons.add({fillColor:myColorC,
strokeColor:myDocument.swatches.item("None")});
myPolygon.paths.item(0).entirePath = [[72, 72], [108, 144], [144, 72]];
myPolygon = myMSO.states.item(3).polygons.add({fillColor:myColorD,
strokeColor:myDocument.swatches.item("None")});
myPolygon.paths.item(0).entirePath = [[144, 72], [72, 108], [144, 144]];

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs5

Table of Contents