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?
Does the problem definitely lie in the event listeners being re-added too soon, rather than the event listeners not being removed properly in the first place?
i.e. have you checked that if you comment out AddEventListeners() then the event listeners not called?