Skip to main content
Liereman
Known Participant
October 11, 2018
Answered

Animate Canvas HTML5 - Stop on specified frame when mouseclick

  • October 11, 2018
  • 1 reply
  • 456 views

I have an Adobe Animate Canvas animation, 100 frames.

Normally the animation should play from frame 1 to frame 100

Only if the user hits a certain button the animation should only play till frame 50.

What code should I use?

    This topic has been closed for replies.
    Correct answer ClayUUID

    In the first frame:

    if (!this.myButton.hasEventListener("click")) {

        this.myButton.addEventListener("click", myButtonClicked.bind(this));

    }

    function myButtonClicked() {

        this.stopAt50 = true;

    }

    If your timeline doesn't loop, you don't need the check around the listener assignment.

    Then on frame 50:

    if (this.stopAt50) {

        this.stop();

    }

    1 reply

    ClayUUIDCorrect answer
    Legend
    October 16, 2018

    In the first frame:

    if (!this.myButton.hasEventListener("click")) {

        this.myButton.addEventListener("click", myButtonClicked.bind(this));

    }

    function myButtonClicked() {

        this.stopAt50 = true;

    }

    If your timeline doesn't loop, you don't need the check around the listener assignment.

    Then on frame 50:

    if (this.stopAt50) {

        this.stop();

    }

    Liereman
    LieremanAuthor
    Known Participant
    October 23, 2018

    ClayUUID​, works perfect, thank you very much!