CHAPTER 11: Creating Dynamic Documents Creating Buttons 154
Creating Buttons
Buttons are often used for navigation in dynamic documents. Buttons contain three states, known as
“Normal,” “Rollover,” and “Click,” which, in turn, can contain page items such as rectangles, ovals, text
frames, or images. The button can display only one state at a time; the other states are displayed when
triggered by mouse actions.
Behaviors control what the button does when you perform a specific mouse action. Behaviors correspond
to the Actions shown in the Buttons panel in InDesign’s user interface. Buttons can contain multiple
behaviors.
The following script fragment shows how to create a simple button that displays the next page in an
exported PDF or SWF (for the complete script, refer to SimpleButton). This button makes use of only the
Normal state.
//Given a page "myPage" and a document containing the color "Red"...
//Make a button by converting a page item.
var myRightArrow = myPage.polygons.add({fillColor:myDocument.colors.item("Red"),
name:"GoToNextPageButton"});
myRightArrow.paths.item(0).entirePath = [[72, 72],[144,108],[72, 144]];
var myButton = myPage.buttons.add({geometricBounds:[72, 72, 144, 144]});
myButton.states.item(0).addItemsToState(myRightArrow);
var myGoToNextPageBehavior =
myButton.gotoNextPageBehaviors.add({behaviorEvent:BehaviorEvents.mouseUp});
The following script fragment shows how to create a somewhat more complicated button, containing
page items that change the appearance of each of the three button states. For the complete script, refer to
ButtonStates.