Adobe 0046100128056 Scripting Guide - Page 121
Sample afterNew Event Listener
UPC - 718659087562
View all Adobe 0046100128056 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 121 highlights
CHAPTER 8: Events Sample afterNew Event Listener 121 myString += "\rCurrent: " +myEvent.currentTarget + " " + myEvent.currentTarget.name; myString += "\r\rPhase: " + myGetPhaseName(myEvent.eventPhase ); myString += "\rBubbles: " + myEvent.bubbles; myString += "\r\rCancelable: " +myEvent.cancelable; myString += "\rStopped: " +myEvent.propagationStopped; myString += "\rCanceled: " +myEvent.defaultPrevented; myString += "\r\rTime: " +myEvent.timeStamp; alert(myString); function myGetPhaseName(myPhase){ switch(myPhase){ case EventPhases.atTarget: myPhaseName = "At Target"; break; case EventPhases.bubblingPhase: myPhaseName = "Bubbling"; break; case EventPhases.done: myPhaseName = "Done"; break; case EventPhases.notDispatching: myPhaseName = "Not Dispatching"; break; } return myPhaseName; } } The following sample script shows how to turn off all eventListeners on the application object. For the complete script, see EventListenersOff. #targetengine "session" app.eventListeners.everyItem().remove(); Sample afterNew Event Listener The afterNew event provides a convenient place to add information to the document, such as the user name, the date the document was created, copyright information, and other job-tracking information. The following tutorial script shows how to add this kind of information to a text frame in the slug area of the first master spread in the document (for the complete script, see AfterNew). This script also adds document metadata (also known as file info or XMP information). #targetengine "session" //Creates an event listener that will run after a new document is created. main(); function main(){ var myEventListener = app.eventListeners.add("afterNew", myAfterNewHandler); } function myAfterNewHandler(myEvent){ var myDocument = myEvent.parent; myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points; myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points; myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin; myCreateSlug(myDocument); myAddXMPData(myDocument); function myCreateSlug(myDocument){