Skip to main content
aldor10080202
Participating Frequently
August 28, 2018
Answered

Going back and forth through the Main Timeline

  • August 28, 2018
  • 1 reply
  • 1212 views

Dear all,

I'm working on a HTML5 canvas.

I have two buttons.

By clicking on the first button (BUTTON 1) I go to the next fifth frame and stop there.

By clicking the other button (BUTTON 2) I go back to the first frame (number 0) wherever currentframe the animation is.

Actually, I used this codes:

BUTTON 1:

exportRoot.BUTTON 1.addEventListener("click", fl_ClickToGoToAndStopAtFrame_1.bind(this));

function fl_ClickToGoToAndStopAtFrame_1() {

    exportRoot.gotoAndStop(exportRoot.currentFrame + 5);

}

BUTTON 2:

exportRoot.BUTTON 2.addEventListener("click", fl_ClickToGoToAndStopAtFrame_2.bind(this));

function fl_ClickToGoToAndStopAtFrame_2() {

    exportRoot.gotoAndStop(0);

}

However it happens that when I click on BUTTON 2 it's ok: the animation goes to frame 0

BUT

afterwards, if I newly click on BUTTON 1 it skips several frames: it does not go to frame 5.

What happens?

Do I have to reset the timeline when I go back to frame 0?

I don't really know what happens

Thank you in advance

    This topic has been closed for replies.
    Correct answer kglad

    BUTTON1's code advances by 5 frames: exportRoot.gotoAndStop(exportRoot.currentFrame + 5);

    it does not go to the 5th or so frame.  that would be something like: exportRoot.gotoAndStop(5);

    1 reply

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    August 29, 2018

    BUTTON1's code advances by 5 frames: exportRoot.gotoAndStop(exportRoot.currentFrame + 5);

    it does not go to the 5th or so frame.  that would be something like: exportRoot.gotoAndStop(5);

    Inspiring
    December 22, 2018

    I think the problem is,  when you reach frame 0  again you reach the frame where the functions are defined.

    So the function is defined once more every time you reach frame 0

    You have to put the functions in the global Script and the addEventListener in the first Frame.

    If you want to proof whats happening if the functions are in the first frame put a console.log in the functions

    console.log(exportRoot.currentFrame);

    when you click BUTTON 1 and BUTTON 2 again and again

    you will see that the command will be invoked several times