Skip to main content
Known Participant
November 2, 2018
Answered

What is the code for a next and previous button? - Animate cc html5 -

  • November 2, 2018
  • 4 replies
  • 7877 views

Help!!

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

    Hi.

    I'm supposing you need navigation buttons like those of e-learning training. If that's the case, put this code in the first frame of the timeline in which the buttons are located:

    // prevButton and nextButton are the instance names of the buttons

    this.navigationLoop = true; // set to true or false to enable or disable loop when the current position is the first or the last frame

    if (!this.hasStarted)

    {

         this.prevFrame = function(e)

         {

              if (this.navigationLoop && this.currentFrame == 0)

                  this.gotoAndStop(this.timeline.duration - 1);

              else

                  this.gotoAndStop(this.currentFrame - 1);

         };

         this.nextFrame = function(e)

         {

             if (!this.navigationLoop && this.currentFrame == this.timeline.duration - 1)

                   return;

             this.gotoAndStop(this.currentFrame + 1);

         };

         this.prevButton.on("click", this.prevFrame, this);

         this.nextButton.on("click", this.nextFrame, this);

         this.stop();

         this.hasStarted = true;

    }

    Regards,

    JC

    4 replies

    Participating Frequently
    July 11, 2020

    Thanks Friend. 

    Participating Frequently
    May 18, 2020

    Thank you for posting your code 

     I have a major problem can't seem to work out

    when i use your code to go fwd on a project it seems to work ok

    but when I go back all the movie clips on the pages previous run once ,although they all have stop actions on them, also I tried to add a reset function telling all individual clips to gotoAndStop when prev button clicked does not work all movies all still run once.

    Was simple in flash prev frame next frame.

    any help appreciated 

    peter

     

    Colin Holgate
    Inspiring
    May 18, 2020

    In CreateJS MovieClips stay in memory and remember everything they have done so far. You could have reset routines in all of the movieclips you use, or you could create a new movieclip from the library each time, after deleting the old one if this is the second time around. 

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    November 2, 2018

    Hi.

    I'm supposing you need navigation buttons like those of e-learning training. If that's the case, put this code in the first frame of the timeline in which the buttons are located:

    // prevButton and nextButton are the instance names of the buttons

    this.navigationLoop = true; // set to true or false to enable or disable loop when the current position is the first or the last frame

    if (!this.hasStarted)

    {

         this.prevFrame = function(e)

         {

              if (this.navigationLoop && this.currentFrame == 0)

                  this.gotoAndStop(this.timeline.duration - 1);

              else

                  this.gotoAndStop(this.currentFrame - 1);

         };

         this.nextFrame = function(e)

         {

             if (!this.navigationLoop && this.currentFrame == this.timeline.duration - 1)

                   return;

             this.gotoAndStop(this.currentFrame + 1);

         };

         this.prevButton.on("click", this.prevFrame, this);

         this.nextButton.on("click", this.nextFrame, this);

         this.stop();

         this.hasStarted = true;

    }

    Regards,

    JC

    svendkrAuthor
    Known Participant
    November 2, 2018

    Awesome, thank you so much!!

    JoãoCésar17023019
    Community Expert
    Community Expert
    November 2, 2018

    You're welcome!

    Legend
    November 2, 2018

    Your question is impossibly vague, like asking "What is the bulb for my light?" Be more specific.

    svendkrAuthor
    Known Participant
    November 2, 2018

    I have 60 frames in a movie, each frame has a stop command, there are 2 arrow buttons (previous and next) at the bottom. What is the javascript to make them go to next and previous frames?? there use to be a nextframe snippet in Flash but not in Animate?