Skip to main content
Participant
May 16, 2024 12:50 PM UTC
Answered

How to run code only on start up

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 is closed to new replies. Start a new post to keep the conversation going.
    JoãoCésar17023019
    JoãoCésar17023019Correct answer
    Community Expert
    May 16, 2024 1:07 PM UTC

    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 1:08 PM UTC

    assuming html5/canvas

     

    if(!this.alreadyExecuted){

    this.alreadyExecuted=true;

    .

    .

    // code to execute once

    }

    Translate
    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    May 16, 2024 1:07 PM UTC

    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

    Translate