2 Replies Latest reply on Jan 5, 2011 7:08 AM by david_a_clark

    How To Prevent Recursive (Vicious Circle) Events

    mlavie Level 1

      I am using the IDScriptingEventAdapter to capture the movement of PageItem's on the page, as follows:


          var adapter:IDScriptingEventAdapter = IDScriptingEventAdapter.getInstance();
          adapter.addEventListener(com.adobe.indesign.Event.AFTER_SELECTION_ATT RIBUTE_CHANGED, listener);
          adapter.addEventListener(com.adobe.indesign.Event.AFTER_SELECTION_CHA NGED, listener);


      The problem is that the listener() method contains commands which themselves move PageItem's - thereby firing itself recursively in a vicuous circle - thus causing stack overflow.


      I tried this, but it doesn't help:


         public function listener(event:*):void
          RemoveEventListeners(); // Removes the listener which fired the event
          MoveArounfPageItems(); // Move around PgaeItem's
          AddEventListeners(); // Put the listeners back


      I thought that removing the listeners would help, but apparently they are put back BEFORE the moved PageItem's fire their events.


      What can I do?