Skip to main content
Inspiring
Jun 18, 2024 11:28 AM UTC
Answered

HTML5

Hi guys, trying a new solution to a problem. Is it possible to have different movies play on the main timeline depending on which frame the main timeline is currently on when a button is clicked? This is the code I have tried but not working. Any help would be greatly apreciated!

 

this.fire2.addEventListener("click", fire.bind(this));
function fire()
{

 

if (this.currentFrame > 1 && this.currentFrame < 14)
{
this.shit2.visible=true;
this.shit2.play();
}

else if (this.currentFrame > 13 && this.currentFrame < 18)
{
this.pepe.visible=false;
this.shit16.visible=true;
this.shit16.play();
}

 

else (this.currentFrame > 17 && this.currentFrame <25)
{
this.shit19.visible=true;
this.shit19.play();
}


}

    This topic is closed to new replies. Start a new post to keep the conversation going.
    Neal37963021vjxtCorrect answer
    Inspiring
    Jun 18, 2024 5:53 PM UTC

    Thanks for the reply! I don't know what was wrong but it's working now.

    BUT when using the if, if else and else statements, the movieClips were playing over each other in certain parts.

    SO I went with 3 if statments instead and now they run smooth and separated? Don't know why.

    So ->

    this.fire2.addEventListener("click", fire.bind(this));
    function fire()
    {
    //early shot
    if (this.currentFrame > 1 && this.currentFrame < 14)
    {
    this.shit2.visible=true;
    this.shit2.play();
    }
    //sweet shot
    if (this.currentFrame > 13 && this.currentFrame < 18)
    {
    this.pepe.visible=false;
    this.shit16.visible=true;
    this.shit16.play();
    }

    //late shot
    if (this.currentFrame > 17 && this.currentFrame < 29)
    {
    this.shit19.visible=true;
    this.shit19.play();
    }
    }

    5 replies

    kglad
    Community Expert
    Community Expert
    Jun 18, 2024 2:22 PM UTC

    check your developer console for errors.  otherwise, that should work if fire2 is clicked when the timeline containing the code is between the 3rd and 25th frames.

    Translate
    Neal37963021vjxtAuthorCorrect answer
    Inspiring
    Jun 18, 2024 5:53 PM UTC

    Thanks for the reply! I don't know what was wrong but it's working now.

    BUT when using the if, if else and else statements, the movieClips were playing over each other in certain parts.

    SO I went with 3 if statments instead and now they run smooth and separated? Don't know why.

    So ->

    this.fire2.addEventListener("click", fire.bind(this));
    function fire()
    {
    //early shot
    if (this.currentFrame > 1 && this.currentFrame < 14)
    {
    this.shit2.visible=true;
    this.shit2.play();
    }
    //sweet shot
    if (this.currentFrame > 13 && this.currentFrame < 18)
    {
    this.pepe.visible=false;
    this.shit16.visible=true;
    this.shit16.play();
    }

    //late shot
    if (this.currentFrame > 17 && this.currentFrame < 29)
    {
    this.shit19.visible=true;
    this.shit19.play();
    }
    }

    Translate
    kglad
    Community Expert
    Community Expert
    Jun 19, 2024 1:46 AM UTC

    you're welcome.

    Translate
    nurba
    Participating Frequently
    Jun 18, 2024 12:16 PM UTC

    is this.fire2 on the main timeline?

     

    this.shit16, this.shit2, this.shit19 are the in this.fire2 movieclip?

    Translate
    Inspiring
    Jun 18, 2024 5:44 PM UTC

    thanks for the reply! No fire2 is actually button that controls 3 movie clips depending on the position of the current frame.

    Translate