Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Script onDraw Button ‘mouseup’ event not triggered in After Effects

  • Script onDraw Button ‘mouseup’ event not triggered in After Effects

    Posted by Vincenzo Imbimbo on January 13, 2025 at 6:03 pm

    Hi everyone,

    I’ve been trying to use the onDraw function in After Effects for a button, and everything works fine except for the mouseup event—it doesn’t seem to trigger.

    Here’s my script:

    var icons1 = { normal1: "base64_encoded_image,

    disable1: base64_encoded_image,

    pressed1: base64_encoded_image,

    rollover1: base64_encoded_image

    };

    var roll1 = ScriptUI.newImage(icons1.rollover1);

    var norm1 = ScriptUI.newImage(icons1.normal1);

    var down1 = ScriptUI.newImage(icons1.pressed1);

    myButton.image = norm1;

    myButton.onDraw = function (state) {

    this.graphics.drawImage(this.image,0,0);

    }

    var mouseEventHandler = function(event) {

    switch (event.type) {

    case 'mouseover':

    event.target.image = roll1;

    break;

    case 'mouseout':

    event.target.image = norm1;

    break;

    case 'mousedown':

    event.target.image = down1;

    break;

    case 'mouseup':

    event.target.image = roll1;

    break;

    default:

    event.target.image = norm1;

    }

    event.target.notify("onDraw");

    }

    myButton.addEventListener('mouseover', mouseEventHandler, false);

    myButton.addEventListener('mouseout', mouseEventHandler, false);

    myButton.addEventListener('mousedown', mouseEventHandler, false);

    myButton.addEventListener('mouseup', mouseEventHandler, false);

    It works fine for mouseover, mousedown, and mouseout, but the mouseup event doesn’t seem to trigger in After Effects. However, I’ve found that the mouseup event does work as expected when I use a left click—which is a bit strange.

    Has anyone else encountered this? Any help would be appreciated!

    Nir Vanaskitz replied 4 weeks ago 2 Members · 1 Reply
  • 1 Reply
  • Nir Vanaskitz

    January 20, 2025 at 8:03 pm

    Hi Vincenzo,

    It looks like you’re running into a common quirk with onDraw and mouse events in After Effects’ ScriptUI. The mouseup event can indeed be a bit finicky in AE, particularly when it’s tied to custom image updates like yours.

    The key issue here is that After Effects sometimes treats the mouseup event differently depending on whether the mouse has moved during the click. If there’s even a slight drag, it might not register the mouseup properly.

    To work around this, you can ensure the mouseup is captured reliably by tweaking the event handling. Instead of directly relying on mouseup, try combining it with click (which generally fires after a mouseup in AE):

    myButton.addEventListener('click', mouseEventHandler, false);

    The click event often provides more consistent results in this context and can serve as a catch-all for when mouseup doesn’t behave as expected. You might also consider using a combination of mousedown and mouseout for specific state resets if needed.

    Hope this helps!

    Best,

    Nir-Vana

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy