How To Prevent Recursive (Vicious Circle) Events
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_ATTRIBUTE_CHANGED, listener);
adapter.addEventListener(com.adobe.indesign.Event.AFTER_SELECTION_CHANGED, 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?
TIA,
mlavie