Skip to main content
michaelo41530365
Participant
June 21, 2017
Answered

gotoAndPlay(frame) after "ended"

  • June 21, 2017
  • 1 reply
  • 422 views

Hello,

I was having some trouble playing the main timeline after my video ended.

I am using a custom component for playing youtube/vimeo videos ( https://www.youtube.com/watch?v=pKh80oJxolU​ ).  The component works really well and thanks to the author.  I then went to vimeo site and checked out the player api, to find the different event triggers I could use ( https://developer.vimeo.com/player​ ).

this.stop();

$(document).ready(function(){

   var iframe = $('iframe');

    var player = new Vimeo.Player(iframe);

    player.on('ended', function() {

       console.log("ended");

        this.gotoAndPlay(11);

    });

});

my console.log("ended") is firing; however, the this.gotoAndPlay(11) is not.  Any help would be greatly appreciated. 

This topic has been closed for replies.
Correct answer michaelo41530365

Never mind I figured it out.  this was referring to the player inside the function.  here is the new code that seems to be working

stage = this;

stage.stop();

$(document).ready(function(){

    var iframe = $('iframe');

    var player = new Vimeo.Player(iframe);

    player.on('ended', function() {

  console.log("ended");

        stage.gotoAndPlay(11);

    });

});

1 reply

michaelo41530365
michaelo41530365AuthorCorrect answer
Participant
June 21, 2017

Never mind I figured it out.  this was referring to the player inside the function.  here is the new code that seems to be working

stage = this;

stage.stop();

$(document).ready(function(){

    var iframe = $('iframe');

    var player = new Vimeo.Player(iframe);

    player.on('ended', function() {

  console.log("ended");

        stage.gotoAndPlay(11);

    });

});

Legend
June 21, 2017

DO NOT use "stage" as a global variable name. In fact just don't use stage as any kind of variable at all. Animate already uses stage as a reference to the root stage object.

If you want to control the root timeline, Animate defines "exportRoot" as a reference to it.

michaelo41530365
Participant
June 21, 2017

ty ClayUUID, will change this and keep in mind for later.  appreciate the help