Skip to main content
Known Participant
July 31, 2023
Question

Next and previous buttons in HTML5

  • July 31, 2023
  • 1 reply
  • 716 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
    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

    Dear CJ 

    Thanks for your help

    Is there a way to use your code with the buttons on the main timline and  the digits mc on its own movie clip, as  i need to transfer the digits reading from lh to rh side . The functioinality is lice this you have 2 frequency readings one 

    active one standby when you slect a frequency using the prev and next buttons in standby the frequencies change positions when you hit a transfer switch. The standby frequency is the only one that you can change, my concept to have four mc and just transfer the time position when you select  to transfer. Two MC provide the digits display, two are control mc that track the displays and set up the timeline position for the transfer because they will remember where the active frequency and the standby frequency are. Is there a better way to this as when I transfer the the digit infomation from standby to active the timeline position of the active frequency is lost therefore to set up the standby display I need to set up a storage of the timeline position, could this be accomplished using an array to store a variable related to the digits mc current frame?.

    Best regards

    Peter

     

    Known Participant
    August 12, 2023

    my error.  that should be:

     

    this.prevbtn.addEventListener("click", prevF.bind(this));

    this.nextbtn.addEventListener("click", nextF.bind(this));

     

    function prevF(){
    if(this.meg_mc.currentFrame>0){
    this.meg_mc.gotoAndStop(this.meg_mc.currentFrame-1);
    }
    }
    function nextF(){
    if(this.meg_mc.currentFrame<this.meg_mc.totalFrames-1){
    this.meg_mc.gotoAndStop(this.meg_mc.currentFrame+1);
    }
    }


    Thank you very much Kglad

    That works well did not know I needed the scope of the mc inside the gotoAndPlay action.

    Best Regards

    Peter