Skip to main content
Inspiring
May 10, 2021
Question

Stop after certain number of frames

  • May 10, 2021
  • 2 replies
  • 1166 views

Hello there, 

does anyone know how to stop an animation after a certain number of frames?

I don't want to put a "this.stop();" keyframe in the timeline, I want a piece of code which stop the animation.

For examle, I'm trying: 

this.button.addEventListener("click", goAnim.bind(this));
function goAnim() {
this.animation.play();
if (this.animation.currentFrame==37) {
this.animation.stop();
}
}
but it doesn't work. 
All of this because I need the animation to stop at certain frame and then gotoAndPlay another one.
Any ideas?
Thanks in advance

 

    This topic has been closed for replies.

    2 replies

    Brainiac
    May 10, 2021

    The correct way to do this is to put a this.stop(); on the timeline. Why do you not want to do it the correct way?

    Paolo5EF8Author
    Inspiring
    May 11, 2021

    Because in my animation I have a shape morphing. It goes from shape1 to circle to shape2 and so on until shape 6. It works on scroll, but I also have buttons on the left so that if I'm at shape2 and want to go to shape6 it should go from shape2 to circle and from circle to shape6, bypassing the frames in between. 

    If I put this.stop(); in the timeline the I would have to scroll two times to go from shape1 to shape2.

    Paolo5EF8Author
    Inspiring
    May 11, 2021

    Ideally the code should be something like this, so that I can wrtie down the different options, depending on which shape I am at. Problem is that it doesn't work.

     

    this.btn_two.addEventListener("click", goTwo.bind(this));
    function goTwo(){
         if(this.mc.currentFrame==//number){
              this.mc.play();
              if(this.mc.currentFrame==//number){
                   this.mc.gotoAndPlay(//number)
    }
    }
    }
    kglad
    Community Expert
    May 10, 2021

    you need to start a loop (eg, enterframe) to repeatedly check if the current frame is the sought frame.

    Paolo5EF8Author
    Inspiring
    May 10, 2021

    Would you mind writing down the code?

    I'm kinda new at coding and not that skilled yet