Adobe 0046100128056 Scripting Guide - Page 118
Events, Understanding the Event Scripting Model, About event properties and event propagation
UPC - 718659087562
View all Adobe 0046100128056 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 118 highlights
8 Events InDesign scripting can respond to common application and document events, such as opening a file, creating a new file, printing, and importing text and graphic files from disk. In InDesign scripting, the event object responds to an event that occurs in the application. Scripts can be attached to events using the eventListener scripting object. Scripts that use events are the same as other scripts-the only difference is that they run automatically when the corresponding event occurs, rather than being run by the user (from the Scripts palette). This chapter shows how to work with InDesign event scripting. The sample scripts in this chapter are presented in order of complexity, starting with very simple scripts and building toward more complex operations. We assume that you have already read Adobe InDesign CS5 Scripting Tutorial and know how to create, install, and run a script. For a discussion of events related to menus, see Chapter 9, "Menus." The InDesign event scripting model is similar to the Worldwide Web Consortium (W3C) recommendation for Document Object Model Events. For more information, see http://www.w3c.org. Understanding the Event Scripting Model The InDesign event scripting model consists of a series of objects that correspond to the events that occur as you work with the application. The first object is the event, which corresponds to one of a limited series of actions in the InDesign user interface (or corresponding actions triggered by scripts). To respond to an event, you register an eventListener with an object capable of receiving the event. When the specified event reaches the object, the eventListener executes the script function defined in its handler function (which can be either a script function or a reference to a script file on disk). You can view the available events using the Object Model Viewer in the ExtendScript Toolkit. In the ExtendScript Toolkit, select the Event class, then click Class in the Types list to display a list of available event types in the Properties and Methods list. About event properties and event propagation When an action-whether initiated by a user or by a script-triggers an event, the event can spread, or propagate, through the scripting objects capable of responding to the event. When an event reaches an object that has an eventListener registered for that event, the eventListener is triggered by the event. An event can be handled by more than one object as it propagates. There are two types of event propagation: X None - Only the eventListeners registered to the event target are triggered by the event. The beforeDisplay event is an example of an event that does not propagate. X Bubbling - The event starts propagation at its target and triggers any qualifying eventListeners registered to the target. The event then proceeds upward through the scripting object model, 118