Skip to main content
toma1148409
Participant
January 28, 2019
Answered

Loop the beginning of the animation X times snd then go to the end frame

  • January 28, 2019
  • 1 reply
  • 446 views

How do I loop the beginning of the animation and only once it is played make the animation proceed to the end? Lets say I have 5 seconds animation: I want first 3 seconds to loop 3 times and only after it is done I want the animation to be played full (5 seconds). Is there any way to do that?

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

    Hi.

    Put the code below in the end of the loop section. For example: your animation has 5 seconds, so put this code in the 3rd second):

    JavaScript code:

    if (!this.count)

        this.count = 0;

    if (this.count++ < 3)

        this.gotoAndPlay(0);

    OR

    AS3 code:

    if (!this.firstTime)

    {

        var count:uint = 0;

        this.firstTime = true;

    }

    if (count++ < 3)

        gotoAndPlay(1);

    But, if you your intended output is a video, I do recommend you to wrap the loop part inside of a Graphic symbol instance and then paste it three times in sequence so that you won't have a hard time exporting your animation later.

    I hope this helps.

    Regards,

    JC

    1 reply

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    January 28, 2019

    Hi.

    Put the code below in the end of the loop section. For example: your animation has 5 seconds, so put this code in the 3rd second):

    JavaScript code:

    if (!this.count)

        this.count = 0;

    if (this.count++ < 3)

        this.gotoAndPlay(0);

    OR

    AS3 code:

    if (!this.firstTime)

    {

        var count:uint = 0;

        this.firstTime = true;

    }

    if (count++ < 3)

        gotoAndPlay(1);

    But, if you your intended output is a video, I do recommend you to wrap the loop part inside of a Graphic symbol instance and then paste it three times in sequence so that you won't have a hard time exporting your animation later.

    I hope this helps.

    Regards,

    JC

    kdmemory
    Inspiring
    January 29, 2019

    Hi João

    hope you are well. I can't wrap my head around it. Yesterday I tried to answer this question but gave up because my code was toooo long and wound up. It needed an easy going solution.

    How ever I tried your javascript solution and it loops the first part 4times instead of 3.

    When playhead reaches this frame

    1st time: this.count++ = 1

    2nd time: this.count++ = 2

    3rd time: this.count++ = 3 -> ergo not smaller than 3, it doesn't fulfill the condition

    but it loops a fourth time  - why???

    Klaus

    JoãoCésar17023019
    Community Expert
    Community Expert
    January 29, 2019

    Hi, Klaus!

    What I understand is that the OP wants the playhead to go from 0 to 3 three times and then again a fourth time but continuing until the end.

    Like this:

    0 _______________ 3

    0 _______________ 3

    0 _______________ 3

    0 _______________ 3________ 5

    Also, please notice that when the check happens, the value is still not incremented.

    This...

    this.count = 0;

    console.log(this.count); // 0

    console.log(this.count++); // 0

    console.log(this.count); // 1

    ... is not the same as this:

    this.count = 0;

    console.log(this.count); // 0

    console.log(++this.count); // 1

    console.log(this.count); // 1

    Please let me know if I missed something or if there's something to add.

    Regards,

    JC