0 Replies Latest reply on Jan 29, 2014 1:07 PM by creativejoan0425

    EventListener in Book

    creativejoan0425 Level 1

      I have a login script, i just put a part of it, i add an eventListener in a document, that can beforePrint will update the user id, but I found that can't work in booklet, I try to change something in my doc and print a booklet, but the user id will change, it is eventListener can't active in book?

      funEventListener();

       

      function funEventListener() {

                var myEventNames = ["beforeQuit", "beforeOpen", "afterNew", "afterOpen", "beforeClose", "afterSave", "afterSaveAs", "afterSaveACopy", "afterPrint", "afterExport", "beforeSave", "beforeSaveAs", "beforeSaveACopy", "beforePrint", "beforeExport"];

                for (var i = 0; i < myEventNames.length; i++) {

                          app.addEventListener(myEventNames[i], funEvent);

                }

       

       

                if (myLog_status == "undefined" && myEvent.eventType != "beforeQuit") {

                          myEvent.stopPropagation();

                          myEvent.preventDefault();

                          return;

                }

                var myString = "";

                if (myEvent.target.constructor.name == "Document") {

                          myDocument = myEvent.target;

                          if (myEvent.eventType == "afterNew") myString = "Opened a New Document.";

                          if (myEvent.eventType == "afterOpen") myString = "Opened File " + (myDocument.saved ? myDocument.fullName : myDocument.name + " [Converted]");

                          if (myEvent.eventType == "beforeClose") myString = myDocument.saved ? "Closed File " + myDocument.fullName : "Closed New Document without saving.";

                          if (myEvent.eventType == "afterSave") myString = "Saved File " + myDocument.fullName;

                          if (myEvent.eventType == "afterSaveAs") myString = "Saved File (Save As) " + myDocument.fullName;

                          if (myEvent.eventType == "afterSaveACopy") myString = "Saved File (Save A Copy) " + myDocument.fullName;

                          if (myEvent.eventType == "afterPrint") myString = myDocument.saved ? "Printed " + myDocument.fullName : "Printed New Document.";

               if (myEvent.eventType == "afterExport") myString = myDocument.saved ? "Exported " + myDocument.fullName : "Exported New Document.";

               if (myEvent.eventType == "beforeSave" || myEvent.eventType == "beforeSaveAs" || myEvent.eventType == "beforeSaveACopy" || myEvent.eventType == "beforePrint" || myEvent.eventType == "beforeExport") {

                                    for (var i = 0; i < app.documents.length; i++) {

                                              if (app.documents[i].undoHistory.length > 0) {

                                                        if (app.documents[i].textVariables.item("User_id") != null) {

                                                                  app.documents[i].textVariables.item("User_id").variableOptions.contents = myLog_status;

                                                        }

                                              }

                                    }

                          }

                } else if (myEvent.target.constructor.name == "LayoutWindow") {

                          if (myEvent.eventType == "afterOpen") {

                                    app.activeDocument.stories.everyItem().trackChanges = true;

                          }

                }

                if (myString) funWriteLogFile(myLog_status, myString);

       

       

                function funGetPhaseName(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;

                }

      }