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

Multiple javascript actions on button click

New Here ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

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!

 

Views

875

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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');

});

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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();

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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