Skip to main content
erlingg27797165
Known Participant
June 22, 2018
Answered

Button only working once

  • June 22, 2018
  • 2 replies
  • 591 views

Hello!

So I've got this button set up in Animate CC with HTML that I'm going to use for navigating forward to "next slide". However, this function does only work the first time I press the button. What's wrong?

- In actions @ frame 1 of main timeline (labels are in Norwegian)

this.Knapp.addEventListener("click", fl_ClickToGoToAndStopAtFrame.bind(this));

function fl_ClickToGoToAndStopAtFrame() {

  if (this.Tekstboks.currentFrame = "Intro") {

  this.Tekstboks.gotoAndStop("Spredning");

  } else if (this.Tekstboks.currentFrame = "Spredning") {

  this.Tekstboks.gotoAndStop("Reaksjon1");

  } else if (this.Tekstboks.currentFrame = "Reaksjon1") {

  this.Tekstboks.gotoAndStop("ElBevegelse");

  } else if (this.Tekstboks.currentFrame = "ElBevegelse") {

  this.Tekstboks.gotoAndStop("Reaksjon2");

  } else if (this.Tekstboks.currentFrame = "Reaksjon2") {

  this.Tekstboks.gotoAndStop("Reaksjon3");

  } else if (this.Tekstboks.currentFrame = "Reaksjon3") {

  this.Tekstboks.gotoAndStop("Samtidig");

  } else if (this.Tekstboks.currentFrame = "Samtidig") {

  this.Tekstboks.gotoAndStop("Elektrisitet");

  } else if (this.Tekstboks.currentFrame = "Elektrisitet") {

  this.Tekstboks.gotoAndStop("Likevekt");

  } else if (this.Tekstboks.currentFrame = "Likevekt") {

  this.Tekstboks.gotoAndStop("Slutt");

  } else if (this.Tekstboks.currentFrame = "Slutt") {

  this.Tekstboks.gotoAndStop("Intro");

  }

}

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    Oh, sorry. There's another thing I didn't notice at first.

    Besides of using currentLabel, you have to use the equality operator (==) not the assignment operator (=).

    2 replies

    Legend
    June 22, 2018

    erlingg27797165  wrote

    this.Knapp.addEventListener("click", fl_ClickToGoToAndStopAtFrame.bind(this));

    function fl_ClickToGoToAndStopAtFrame() {

      if (this.Tekstboks.currentFrame = "Intro") {

      this.Tekstboks.gotoAndStop("Spredning");

      } else if (this.Tekstboks.currentFrame = "Spredning") {

      this.Tekstboks.gotoAndStop("Reaksjon1");

      } else if (this.Tekstboks.currentFrame = "Reaksjon1") {

      this.Tekstboks.gotoAndStop("ElBevegelse");

      } else if (this.Tekstboks.currentFrame = "ElBevegelse") {

      this.Tekstboks.gotoAndStop("Reaksjon2");

      } else if (this.Tekstboks.currentFrame = "Reaksjon2") {

      this.Tekstboks.gotoAndStop("Reaksjon3");

      } else if (this.Tekstboks.currentFrame = "Reaksjon3") {

      this.Tekstboks.gotoAndStop("Samtidig");

      } else if (this.Tekstboks.currentFrame = "Samtidig") {

      this.Tekstboks.gotoAndStop("Elektrisitet");

      } else if (this.Tekstboks.currentFrame = "Elektrisitet") {

      this.Tekstboks.gotoAndStop("Likevekt");

      } else if (this.Tekstboks.currentFrame = "Likevekt") {

      this.Tekstboks.gotoAndStop("Slutt");

      } else if (this.Tekstboks.currentFrame = "Slutt") {

      this.Tekstboks.gotoAndStop("Intro");

      }

    }

    Please, please just use this instead:

    this.Knapp.on("click", KnappClicked, this);

    function KnappClicked() {

        var labels = ["Intro", "Spredning", "Reaksjon1", "ElBevegelse", "Reaksjon2", "Reaksjon3", "Samtidig", "Elektrisitet", "Likevekt", "Slutt", "Intro"];

        this.gotoAndStop(labels[labels.indexOf(this.currentLabel) + 1]);

    }

    erlingg27797165
    Known Participant
    June 22, 2018

    Haha!

    yes, I agree it looks messy. Sadly there are a lot of other things happening as well for each click, so it has to be like that (the more complete code looks even worse).

    Legend
    June 22, 2018

    Then that's exactly what switch is for.

    switch (this.Tekstboks.currentFrame) {

        case "Intro":

            this.Tekstboks.gotoAndStop("Spredning");

            break;

        case "Spredning":

            this.Tekstboks.gotoAndStop("Reaksjon1");

            break;

        case "Reaksjon1":

            this.Tekstboks.gotoAndStop("ElBevegelse");

            break;

       // etc...

    }

    JoãoCésar17023019
    Community Expert
    Community Expert
    June 22, 2018

    Hi.

    It's because you are comparing the currentFrame property, which is a integer equal or bigger than 0, to a string.

    Instead of currentFrame use currentLabel.

    Regards,

    JC

    erlingg27797165
    Known Participant
    June 22, 2018

    Sadly, no. This doesn't help.

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    June 22, 2018

    Oh, sorry. There's another thing I didn't notice at first.

    Besides of using currentLabel, you have to use the equality operator (==) not the assignment operator (=).