Skip to main content
Inspiring
February 7, 2018
Answered

How do I put event listeners in the global script?

  • February 7, 2018
  • 1 reply
  • 682 views

I simply want to place event listeners in the Animate CC global script so that I am not cluttering up frame 1.  How would  I put the following script in the global script window and change it so the listener can actually find the instance "nextBut" at the root level? Thanks in advance.

this.nextBut.addEventListener("click", doNext.bind(this));

function doNext() {

  alert("foo")

}

    This topic has been closed for replies.
    Correct answer ClayUUID

    It's probably a bad idea to put bare code in the global script. If you have initialization code that needs to be run, wrap it in an init function and then call it in the first frame.

    Or just "clutter up" frame 1. Animate doesn't care. Worry about what works, not IDE aesthetics.

    1 reply

    ClayUUIDCorrect answer
    Legend
    February 7, 2018

    It's probably a bad idea to put bare code in the global script. If you have initialization code that needs to be run, wrap it in an init function and then call it in the first frame.

    Or just "clutter up" frame 1. Animate doesn't care. Worry about what works, not IDE aesthetics.