Skip to main content
Known Participant
May 26, 2020
Question

Multiple javascript actions on button click

  • May 26, 2020
  • 2 replies
  • 999 views

Hi,

I'm new to Adobe Animate and I don't know Javascript but I've been using the wizard to add some basic functionality and everything has worked so far. But now I need multiple things to happen on 1 button click as follows:

  • Go to the next frame and play next 20 frames
  • Then go to the main timeline and go to a frame and play

I'm using a Movie Clip and this is the code I have right now, but I can only get it to do one or the other, it's ignoring the first action.

var _this = this;

_this.btn_emotional_reduced.on('click', function(){

_this.gotoAndPlay('currentFrame + 1');
_this.parent.gotoAndPlay('test');
});

 

Any help would be greatly appreciated. Thanks!

 

    This topic has been closed for replies.

    2 replies

    Legend
    May 26, 2020

    The first action is being ignored because you're literally telling it to go to the frame labeled "currentFrame + 1", which I'm assuming does not exist. What you meant to do there was:

     

    _this.gotoAndPlay(_this.currentFrame + 1);

     

    But y'know, there's a much simpler way to do this:

     

    _this.play();

     

    Known Participant
    May 26, 2020

    Thanks Clay, "currentFrame + 1" was working on it's own, just not when I try to add a second function, but I did change it.

     

    Thanks for the suggestion.

    Patti

    Colin Holgate
    Inspiring
    May 26, 2020

    setTimeout() would be an easy solution. You can set up as many things as you like to happen at an exact time.

    This article should get you started:

    https://www.bitdegree.org/learn/javascript-settimeout

    Known Participant
    May 26, 2020

    Thanks Colin but I'm not getting it. If I want it to gotoAndPlay 'intimidation_close' for 1 second and then _this.parent.gotoAndPlay('test'), how do I use setTimeout?

     

    var _this = this;

    _this.btn_emotional_reduced.on('click', function(){

    _this.gotoAndPlay('intimidation_close');
    _this.parent.gotoAndPlay('test');

    });