8 Replies Latest reply on Jun 23, 2010 8:30 AM by stimms-enform

    Error when running script afterOpen

    stimms-enform

      I am trying to get a script working to run as soon as a document is opened in indesign cs4.  The script I have is very simple as it is just a proof of concept

       

      var eventListener1;
      main();

       

      function main()
      {
              eventListener1 = app.addEventListener("afterOpen", openEvent, false);
              alert("listener registered")
      }

       

      function openEvent(eventInfo)
      {
              alert('open');
      }

       

      I have this script in the startup folder and, indeed, when I start indesing I do get a message box with 'listener registered'.  However when I open a documentI get this error:

       

      JavaScript Error!


      Error Number: 30476

      Error String: The requested action could not be completed because the object no longer exists.

       

      I have tried a few different things like moving the openEvent function into an inline funciton in the call to addEventListener but nothing is working.  Any idea what I'm doing wrong in this very simple script?