Skip to main content
Participant
May 16, 2024
Answered

How to run code only on start up

  • May 16, 2024
  • 2 replies
  • 270 views

How can i run code once when the animation loads? Everything works fine but i now want to add some code to the start to set up, like stop movieclip and hide objects stuff like that, but if i put it at the top of my script, it runs every time i get to that frame.

 

Thanks

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

    Hi.

     

    Create a custom boolean flag in the first frame of the main timeline. Like this:

    if (!this.started)
    {
        // your startup code goes here
        this.started = true;
    }

     

    I hope this helps.

     

    Regards,

    JC

    2 replies

    kglad
    Community Expert
    Community Expert
    May 16, 2024

    assuming html5/canvas

     

    if(!this.alreadyExecuted){

    this.alreadyExecuted=true;

    .

    .

    // code to execute once

    }

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    May 16, 2024

    Hi.

     

    Create a custom boolean flag in the first frame of the main timeline. Like this:

    if (!this.started)
    {
        // your startup code goes here
        this.started = true;
    }

     

    I hope this helps.

     

    Regards,

    JC