Skip to main content
Inspiring
June 18, 2024
Answered

HTML5

  • June 18, 2024
  • 2 replies
  • 451 views

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 has been closed for replies.
    Correct answer Neal37963021vjxt

    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();
    }
    }

    2 replies

    kglad
    Community Expert
    Community Expert
    June 18, 2024

    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.

    Neal37963021vjxtAuthorCorrect answer
    Inspiring
    June 18, 2024

    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();
    }
    }

    kglad
    Community Expert
    Community Expert
    June 19, 2024

    you're welcome.

    nurba
    Participating Frequently
    June 18, 2024

    is this.fire2 on the main timeline?

     

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

    Inspiring
    June 18, 2024

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