Skip to main content
Inspiring
August 17, 2019
Question

gotoAndPlay inside function bypasses stop

  • August 17, 2019
  • 1 reply
  • 485 views

I've got a simple 'slider' movieclip which moves from left to right with this.stop() at frame 0, 40 and 80. In the root I've got a button which is set like this:

this.stop();

target = this.sliding;

this.buttonright.addEventListener("click", slideright.bind(this));

function slideright() {

  target.gotoAndPlay(39);

}

So when I click it it starts playing that slider movieclip from its frame 39. Which works the first time: it plays from frame 39 and stops at frame 40 as there is a this.stop() there. The second time I click the button however it starts playing from the slider's frame 39 again, but then bypasses the this.stop() that is in its frame 40 and continues to play until it reaches frame 80.

Why is this and how can I prevent it?

I know it doesn't make much sense playing that clip from frame 39 when it already stops at 40. But the point is that when I use gotoAndPlay(1) to gotoAndPlay(38) it works and always stops at frame 40. But when I use gotoAndPlay(39) it only works the first time and the next time I click the this.stop() is bypassed for some reason. And I would like to know why and how to fix it.

The file if you're interested: WeTransfer

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    August 17, 2019

    your sliding movieclip this.stop()'s are in frames 0, 39 and 79, not 0, 40 and 80.  ie, fix your code or your stops.

    jiggy1965Author
    Inspiring
    August 17, 2019

    Don't think so? In my movieclips I've got my this.stop();s in frames 40 and 80.

    kglad
    Community Expert
    Community Expert
    August 17, 2019

    canvas/html5 frames are numbered starting with frame 0.  what looks to you like frames 40 and 80, are frames 39 and 79.

    you can use alert(this.currentFrame) or console.log(this.currentFrame) on any frame to see the correct reference you should be using.