Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Multiple javascript actions on button click

New Here ,
May 26, 2020 May 26, 2020

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!

 

963
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 26, 2020 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 26, 2020 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');

});

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 27, 2020 May 27, 2020
LATEST

Hi Colin,

Thanks again for your help. The setTimeout code worked, as follows:

var _this = this;

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

_this.gotoAndPlay('intimidation_close');

setTimeout(function () {
_this.parent.gotoAndPlay('emotional'); }, 1000);

});

Thanks,

Patti

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 26, 2020 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();

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 26, 2020 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines