Skip to main content
Known Participant
August 15, 2023
Question

gotoAndPlay only works once

  • August 15, 2023
  • 2 replies
  • 955 views

Hi,

I have an Animate file that was originally created in 2020 that is used on a client's website, so it uses HTML5 canvas. My client asked for some minor changes but now when I publish the previous file (without editing) it's not working properly. 

 

On the main timeline I have a pie shaped graphic, and each section is a button. When the button is clicked it goes to a specific frame label on the parent timeline and plays a movie clip. In the individual movie clips, it plays part of the animation and then stops, and when they click on another button, it plays the rest of the current movie clip, then goes back to the parent timeline to the specified label and plays that. The following is the Action on the frame where it has been stopped, within the individual movie clip:

 

this.stop();
 
var _this = this;
 
_this.btn_intimidation_reduced.on('click', function(){
 
_this.gotoAndPlay('coercion_close');
 
setTimeout(function () { 
_this.parent.gotoAndPlay('intimidation'); }, 833);
 
});
 
 
var _this = this;
 
_this.btn_emotional_reduced.on('click', function(){
 
_this.gotoAndPlay('coercion_close');
 
setTimeout(function () { 
_this.parent.gotoAndPlay('emotional'); }, 833);
 
});
 
 
var _this = this;
 
_this.btn_isolation_reduced.on('click', function(){
 
_this.gotoAndPlay('coercion_close');
 
setTimeout(function () { 
_this.parent.gotoAndPlay('isolation'); }, 833);
 
});
 
 
var _this = this;
 
_this.btn__minimize_reduced.on('click', function(){
 
_this.gotoAndPlay('coercion_close');
 
setTimeout(function () { 
_this.parent.gotoAndPlay('minimize'); }, 833);
 
});
 
 
var _this = this;
 
_this.btn_children_reduced.on('click', function(){
 
_this.gotoAndPlay('coercion_close');
 
setTimeout(function () { 
_this.parent.gotoAndPlay('children'); }, 833);
 
});
 
 
var _this = this;
 
_this.btn_male_reduced.on('click', function(){
 
_this.gotoAndPlay('coercion_close');
 
setTimeout(function () { 
_this.parent.gotoAndPlay('male'); }, 833);
 
});
 
 
var _this = this;
 
_this.btn_economic_reduced.on('click', function(){
 
_this.gotoAndPlay('coercion_close');
 
setTimeout(function () { 
_this.parent.gotoAndPlay('economic'); }, 833);
 
});

 

 

This works fine, but only once. If they click on any button more than once, it goes to the correct frame label but stops. I've tested every button, and every sequence that I can think of but it always stops working as soon as they click on a button a second time.

 

Thanks, any help would be much appreciated! 

    This topic has been closed for replies.

    2 replies

    Known Participant
    August 16, 2023

    I should also mention that when I publish the animation I get the Output Warning:

    "Frame numbers in EaselJS start at 0 instead of 1. For example, this affects gotoAndStop and gotoAndPlay calls. (38)
    Modifying the transform point in a tween can produce unexpected results. (10)"

    kglad
    Community Expert
    Community Expert
    August 16, 2023

    i don't see a problem with your code (though i dislike the way it appears that your nesting functions) IF none of that code is re-executed via the frame that contains it playing more than once.

    Known Participant
    August 21, 2023

    replace the code you showed with

     

    this.stop();
     
    var _this = this;
    var buttonA = [_this.btn_intimidation_reduced,_this.btn_emotional_reduced, _this.btn_isolation_reduced, _this.btn_minimize_reduced, _this.btn_children_reduced, _this.btn_male_reduced, _this.btn_economic_reduced];
     
    if(!this.alreadyDefined){
    for(var i=0;i<buttonA.length;i++){
    buttonA[i].addEventListener("click",buttonF);
    }
    this.alreadyDefined = true;
    }
     
    function buttonF(e){
    _this.parent_frame = e.currentTarget(buttonA[i].name.split("_")[1]);
    setTimeout(parent_playF,833);
    _this.gotoAndPlay("coercion_close");
    }
    function parent_playF(){
    _this.parent.gotoAndPlay(_this.parent_frame);
    }

    Thanks kglad, I can see that each button will gotoAndPlay "coercion_close" but how do I specify which parent timeline frame each individual button will go to?

    JoãoCésar17023019
    Community Expert
    Community Expert
    August 15, 2023

    Hi.

     

    What does happen if you set the autoReset property of each animation to false?

     

    Also make sure you're not getting any error on the browser's console.

     

    Please let us know.

     

    Regards,

    JC

    Known Participant
    August 15, 2023

    Thanks for the response JoãoCésar. I'm not getting browser console errors.

     

    Sorry I haven't used Animate that many times, and the last time I did was for this project 3 years ago. So I'm not sure if I'm adding the autoReset properly. I tried adding this.autoReset = false; as an Action in the first frame of 1 of the movies as a test but it didn't help (also tried setting it to "true"). And then I tried going to the main timeline and selecting the mc from there and adding but it's not helping.