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

Check if variable is true and play animation.

Explorer ,
Sep 27, 2022 Sep 27, 2022

Copy link to clipboard

Copied

Hello, I want to be able to play an animation if a variable is true. "Checker" is dynamic text for seeing if the var SimpCarbPlay1 is true or false. It works, but what doesn't work is the if statement. That's what I'm really trying to do so when SimpCarbPlay1 is true, it should go to frame 30 and play. 

 

var _this=this;
this.stop()
var SimpCarbPlay1 = "what";

this.checker.text = SimpCarbPlay1;



_this.Ybutton.on('click', MakeTrue);
_this.Bbutton.on('click', MakeFalse);

function MakeTrue() {
	SimpCarbPlay1 = true;
	_this.checker.text = SimpCarbPlay1;
}
function MakeFalse() {
	SimpCarbPlay1 = false;
	_this.checker.text = SimpCarbPlay1;
}


if (SimpCarbPlay1 == true) {
	_this.gotoAndPlay(30);
} 

 

 

beatbum_0-1664348551811.png

thanks for your help.

dr

 

TOPICS
ActionScript

Views

133

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

correct answers 1 Correct answer

Explorer , Sep 29, 2022 Sep 29, 2022

ok I solved it by using a loop:

 

if (v_playAnim1 == true) {
_this.gotoAndPlay("Anim1");
} else {
_this.gotoAndPlay("Looper1")
}

 

This way, it checks over and over again until the variable changes to true.

Votes

Translate

Translate
Community Expert ,
Sep 28, 2022 Sep 28, 2022

Copy link to clipboard

Copied

Hi.

 

The if statement is executed only once and in the beginning. You should run it inside of your functions. Like this:

function MakeTrue()
{
	SimpCarbPlay1 = true;
	_this.checker.text = SimpCarbPlay1;
	
	if (SimpCarbPlay1 == true)
	{
		_this.gotoAndPlay(30);
	}
}

function MakeFalse()
{
	SimpCarbPlay1 = false;
	_this.checker.text = SimpCarbPlay1;
	
	if (SimpCarbPlay1 == true)
	{
		_this.gotoAndPlay(30);
	}
}

 

This code can be further optimized but I'll leave it like this so it's easier to understand.

 

Regards,

JC

 

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
Explorer ,
Sep 28, 2022 Sep 28, 2022

Copy link to clipboard

Copied

ok thanks, that will work but it is depending on clicking the button. In which case I would just say on click go to and play 30. I need it to check if a variable is true or false because the variable will be changing in the parent application. This Adobe Animate module will be embedded inside of Storyline and I want Storyline to change the variable. So that's where my if statement comes in. 

 

I was able to get Animate to communicate to Storyline using this:

//parent.GetPlayer().SetVar("SL_VOchoose", false);

 

But now I want Storyline to communicate down to Animate and let it know when to play the animation. So when Storyline changes the variable to true I want Animate to recognize that and go to and play 30. I hope this is not confusing. And I hope you can help.

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
Explorer ,
Sep 29, 2022 Sep 29, 2022

Copy link to clipboard

Copied

LATEST

ok I solved it by using a loop:

 

if (v_playAnim1 == true) {
_this.gotoAndPlay("Anim1");
} else {
_this.gotoAndPlay("Looper1")
}

 

This way, it checks over and over again until the variable changes to true.

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