Skip to main content
Known Participant
July 31, 2023
Question

Next and previous buttons in HTML5

  • July 31, 2023
  • 1 reply
  • 749 views

Dear all thank you for yor time 

I am making an animation that changes a frequency setting on a radio, to do this I need to have buttons that do both next and previous timline postions and then be able to to advance either one frame or two depending on the position selected. the counter display is in LCD digits which I have turned into vectors as there is not a LCD font in adobe or goolle fonts

.I put the code that CJ suggested on the main timeline with the buttons and it works but when  I put the code and the buttons on the movie clip itself  with the code then refer to the buttons via the movie clip I get an error saying the "digits_mc movie clip is not dfined ". How do I make CJ's code work from within a movie clip work.

this.stop()
stage.enableMouseOver(frequency)
var frameNumber = this.currentFrame;
let root = this;
var frequency = 3;
this.stop()


createjs.Touch.enable(stage);

// 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.digits_mc.prevButton.on("click", this.prevFrame, this);

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

     this.stop();

     this.hasStarted = true;

}

 I also tried putting the code on the main timeline and referencing the nested movie clip but it did not work, I must be doing something wrong but I cant figure out where I am going wrong.

Best regards

Peter

    This topic has been closed for replies.

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    July 31, 2023

    Hi.

     

    Are your code and buttons inside of digits_mc? If so, you should write like this.prevButton instead of this.digits_mc.prevButton, because you already is inside of digits_mc, if I understand correctly what you are doing. The same for other occurrences in the code.

     

    Please let us know.

     

    Regards,

    JC

    Known Participant
    August 1, 2023

    Thanks JC

    I thought I had to add the code to get to the movie clip for the buttons as inside the" digits _mc movie" clip. How does it work that in JS this is not required  but  in AS3 I would have to detail scope to get to the embeded movie clip, when I add an event lisetner such as "click" confused a bit thats all.

    Best Regards Peter