Skip to main content
megamau
Inspiring
September 2, 2016
Answered

Event listeners generate errors while modal windows are shown.

  • September 2, 2016
  • 2 replies
  • 1564 views

Hello all,

I have an interface in script ui that relies on event listeners initialized like this:

var button = palette.add("image", rect);
button.onDraw = buttonDraw;
button.addEventListener('mouseover', onMouse, false);
button.addEventListener('mouseout', onMouse, false);
button.addEventListener('mousedown', onMouse, false);
button.addEventListener('mouseup', onMouse, false);

I need these events so I can change images (fake buttons) when the user moves the mouse over them or clicks one of them. Everything works as it should, until I decided to render something. While rendering in After Effects, a window or something is opened somewhere and it makes all scripts useless, they do not respond to user input at all, and that's fine to me. It works the same for all scripts that I tested.

The real problem is with event listeners. Scripts that use them will generate a background error if any listener is activated. And when the render finishes, AE will show a popup message letting you know about these errors. Also the script interface will stop running completely until you close it an open it again.

The error message is:

"Can not run a script while a modal dialog is waiting for response."

I thought of replacing all listeners with the other type of callback like "onClick", but it seems there's no workaround for "mouseover" or "mouseout".

This is a real issue for my UI, as if the user has my panel docked somewhere in the interface and simply moves the mouse over any of the buttons, he will end up with the error message at the end of the render. There's also nothing I can do to avoid the listeners from running, since after the script is loaded, we lose all control of what's going on with it, no way to remove the listeners temporarily.

Any ideas on how to solve this?

Correct answer megamau

I found a workaround for my problem.

I had to remove the event listenerer "mouseout" when my custom onDraw function was executed as a result of the actual mouse going out (in other words drawing my image in the iddle version). Then, I simply install the "mouseout" event again when the "mouseover" event is fired.

I also tried removing the listener "mouseout" in my onMouseOut function, but it didn't work very well, the only way was to remove it in the custom onDraw.

Another thing I found out is that the "mouseout" event is actually fired 2 times... every time!. Which is surely a bug.

I'll mark this as answered even though this is more like a dirty workaround than an actual fix. I think this is a bug from After Effects (at least).

UQg​ regarding your issue, do you have a thread for it? If not, you should create one, I also have that problem and I'm going to look into it.

2 replies

Participant
January 23, 2025

This remains an issue in 2025, lol. I love CEP, but ScriptUI is still desirable when deploying simple ES tools quickly. Removing the listener when it fires works, but it seems like it can be defeated: When over an element, if you press a hotkey to bring up a modal such as Ctrl+I for File>Import etc., the mouseout never gets a chance to fire and remove itself and thus can still trigger as the modal is active. More rare than usual ineraction, but still causes the error.

UQg
Legend
September 2, 2016

Hello, normally when a dialog window is shown, the rest of AE's UI is disabled, hence eventlisteners are deactivated for the duration of the dialog.

I tried and couldnt reproduce what you describe (launch a panel with a similar button, start a render, hover over the panel while rendering: no error). Can you provide more info about the onMouse function ?

However i'm jumping on this topic because of a very similar problem (Windows7/AE CC2015):

when a native dialog is shown (ie not a script alert, but for instance Edit>Preferences>General), everything in a ScriptUI Panel that has a custom onDraw disappears, and this sometimes persist when the dialog is closed. Given that .onActivate() doesnt work for panels, one has to "reshaw" buttons by hand by hovering over everything that is "missing"...

Xavier

megamau
megamauAuthor
Inspiring
September 2, 2016

Hi,

As it turns out, the culprit is actually the listener "mouseout". I was just creating a simple script to show you the problem, and noticed it was working with the "mouseover" listener, so I added all the others I was using and puff! I also tested with the "keydown" event which also generates the error.

Here the test script:

function TestListeners(thisObj)

{

  var myMainPanel = createUI(thisObj);

    if(this instanceof Panel)

        myMainPanel.show();

  function createUI(thisObj)

    {

        var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "Test", undefined);

  var button = myPanel.add("button", {x:10, y:10, width:50, height:50}, "Test Button");

  button.addEventListener('mouseout', onMouse, false);

  return myPanel;

    }

  function onMouse(event)

  {

  }

}

TestListeners(this);

On another note, I tried to get rid of all events and added a custom onDraw to my buttons and checked there if the mouse was over or the button was clicked. It also crashes. In fact, just adding a custom onDraw to a button returns that error message at the end of the render. Which makes me think that the "mouseout" event is used here as well.

by the way, I also have the same problem with the images disappearing when for eg. the general option window is open. I'm also using a custom onDraw for these images.

megamau
megamauAuthorCorrect answer
Inspiring
September 4, 2016

I found a workaround for my problem.

I had to remove the event listenerer "mouseout" when my custom onDraw function was executed as a result of the actual mouse going out (in other words drawing my image in the iddle version). Then, I simply install the "mouseout" event again when the "mouseover" event is fired.

I also tried removing the listener "mouseout" in my onMouseOut function, but it didn't work very well, the only way was to remove it in the custom onDraw.

Another thing I found out is that the "mouseout" event is actually fired 2 times... every time!. Which is surely a bug.

I'll mark this as answered even though this is more like a dirty workaround than an actual fix. I think this is a bug from After Effects (at least).

UQg​ regarding your issue, do you have a thread for it? If not, you should create one, I also have that problem and I'm going to look into it.