Skip to main content
blckVanta
Participant
February 20, 2018
Answered

Movieclip to gotoAndPlay when root timeline has reached a specific frame

  • February 20, 2018
  • 2 replies
  • 1744 views

Hi,

I’m trying to get a movieclip on my main timeline to jump to a frame when the user has clicked to the next frame, but I don’t want the movieclip to go to that specific frame until the movieclip itself has reach a certain frame.

I bet this is pretty noob question, but I’m probably a bit slow because I’ve tried reading tutorials and everything, but can’t get this simple code to work inside the movie clip:

stop();

if ((root).currentFrame == (3)) {

    root.mc.gotoAndPlay ("loop");

}

else

{

    root.mc.gotoAndPlay (“continue1"));

}

I’ve also tried this:

stop();

{

    if ((root).currentFrame == 3) {

    this.gotoAndPlay(272);

}

else

{

    this.gotoAndPlay(283);

}

}

And many other variations..

I don’t really understand anything anymore about coding..

I just wish someone could tell me how I can get this to work before I do something drastic or my head explodes.

Thanks!

This topic has been closed for replies.
Correct answer kglad

if root.currentFrame <4

        this.gotoAndPlay 272;

    else

        this.gotoAndPlay 283;

i'm not sure that's what you want, but to eliminate syntax errors, use:

if (MovieClip(root).currentFrame <4){

        this.gotoAndPlay(272);

}    else {

        this.gotoAndPlay(283);

}

2 replies

blckVanta
blckVantaAuthor
Participant
February 20, 2018

Thanks for your reply!

I always get somekind of syntax error so the problem is with the code language, that I just don't get.

This is the code that I want to get to work inside the movieclip, but I just don't understand where I need to put brackets, what kind of brackets and why:

if root.currentFrame <4

        this.gotoAndPlay 272;

    else

        this.gotoAndPlay 283;

I've tried looking at different codes and understanding how the brackets work, but everything I try screws up the whole timeline and gives me syntax errors.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
February 20, 2018

if root.currentFrame <4

        this.gotoAndPlay 272;

    else

        this.gotoAndPlay 283;

i'm not sure that's what you want, but to eliminate syntax errors, use:

if (MovieClip(root).currentFrame <4){

        this.gotoAndPlay(272);

}    else {

        this.gotoAndPlay(283);

}

blckVanta
blckVantaAuthor
Participant
February 21, 2018

Awesome! Thanks a bunch now it works!

I thought i had to have the code refer to the movieclip by it's instance name, I didn't understand that the movieclip could refer to the main timeline (root) just by that (MovieClip(root) command without instance names.

kglad
Community Expert
Community Expert
February 20, 2018

after the user clicks, you need to start a loop (eg, enterframe) to repeatedly check the main timeline's currentFrame to see if its reached your specific frame.