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

"if then" help request

New Here ,
Feb 05, 2020 Feb 05, 2020

Copy link to clipboard

Copied

 

first and most important many thanks in advance from a very novice user

i have a very simple HTML5 doc that i could use some assistance in the script-

the essentials are this:

i have 6 unique movie clips (just a still graphic) where only 2 will be visable at a time

6 buttons that will select which 2 objects will be visable-

i am looking for a "if/then" script for a new button to swap visable objects just not sure the correct syntax... something like this but with all possibilities?

--

if

this.grnSqmc.visible = true;
this.bluSqmc.visible = false;
this.redSqmc.visible = false;
this.grnbCrclmc.visible = false;
this.bluCrclmc.visible = true;
this.redCrclmc.visible = false;
 
then
this.grnSqmc.visible = false;
this.bluSqmc.visible = true;
this.redSqmc.visible = false;
this.grnbCrclmc.visible = true;
this.bluCrclmc.visible = false;
this.redCrclmc.visible = false;

 

--

 

 

 

here is what i have that works great for me so far:

 
***
this.grnSqmc.visible = true;
this.bluSqmc.visible = false;
this.redSqmc.visible = false;
this.grnbCrclmc.visible = false;
this.bluCrclmc.visible = true;
this.redCrclmc.visible = false;
 
this.btnshwGrnSq.addEventListener("click", fl_ClickToHide.bind(this));
 
function fl_ClickToHide()
{
this.grnSqmc.visible = true;
this.bluSqmc.visible = false;
this.redSqmc.visible = false;
 
}
 
this.btnshwBluSq.addEventListener("click", fl_ClickToHide_2.bind(this));
 
function fl_ClickToHide_2()
{
this.grnSqmc.visible = false;
this.bluSqmc.visible = true;
this.redSqmc.visible = false;
 
}
 
this.btnshwRedSq.addEventListener("click", fl_ClickToHide_3.bind(this));
 
function fl_ClickToHide_3()
{
this.grnSqmc.visible = false;
this.bluSqmc.visible = false;
this.redSqmc.visible = true;
}
 
this.btnshwGreenCrcl.addEventListener("click", fl_ClickToHide_4.bind(this));
 
function fl_ClickToHide_4()
{
this.grnbCrclmc.visible = true;
this.bluCrclmc.visible = false;
this.redCrclmc.visible = false;
}
 
 
this.btnshwBlueCrcl.addEventListener("click", fl_ClickToHide_5.bind(this));
 
function fl_ClickToHide_5()
{
this.grnbCrclmc.visible = false;
this.bluCrclmc.visible = true;
this.redCrclmc.visible = false;
}
 
this.btnshwRedCrcl.addEventListener("click", fl_ClickToHide_6.bind(this));
 
function fl_ClickToHide_6()
{
this.grnbCrclmc.visible = false;
this.bluCrclmc.visible = false;
this.redCrclmc.visible = true;
}
 
***
 

again thanks in advance!

 

 

TOPICS
ActionScript

Views

156

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
Community Expert ,
Feb 06, 2020 Feb 06, 2020

Copy link to clipboard

Copied

Hi.

 

You're going to need the logical NOT operator.

 

For example:

function toggleVisibility(e)
{
	this.grnSqmc.visible = !this.grnSqmc.visible;
	this.bluSqmc.visible = !this.bluSqmc.visible;
	this.redSqmc.visible = !this.redSqmc.visible;
	this.grnbCrclmc.visible = !this.grnbCrclmc.visible;
	this.bluCrclmc.visible = !this.bluCrclmc.visible;
	this.redCrclmc.visible = !this.redCrclmc.visible;
}

this.stop();
this.yourToggleButton.addEventListener("click", toggleVisibility.bind(this));

 

So

- if something is true and you set it to be NOT true, it will be false;

- if something is false and you set it to be NOT false, it will be true.

 

I hope it makes sense.

 

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
New Here ,
Feb 06, 2020 Feb 06, 2020

Copy link to clipboard

Copied

thank you JC 

 

that worked! but the results are pretty exact in that the 2 NOT visable squares and 2 NOT visable circles become visable- 

what i am hoping for is if a green square and red circle is visable, the toggle will make green circle and red square visable... while leaving the 2 blue object not visable at all since they were not initially selected -

that is where my "if/then" approach came from... "if blue sqaure and red circle are visable then toggle to red square and blue circle ignor green square green circle"

is this possible?

again, many thanks in advance!!

 

 

 

 

 

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 ,
Feb 06, 2020 Feb 06, 2020

Copy link to clipboard

Copied

First, as you see many times in your own code, "visible",  not "visable".

 

Second, all you need is the && logical AND operator.

 

if (condition1 && condition2) {

     do something

}

 

You can have as many conditions as you want. You could even do something crazy like:

if (this.grnSqmc.visible && !this.bluSqmc.visible && !this.redSqmc.visible && !this.grnbCrclmc.visible && this.bluCrclmc.visible && !this.redCrclmc.visible) {
	this.grnSqmc.visible = false;
	this.bluSqmc.visible = true;
	this.redSqmc.visible = false;
	this.grnbCrclmc.visible = true;
	this.bluCrclmc.visible = false;
	this.redCrclmc.visible = false;
}

The ! prefix mean NOT. It flips Boolean values from True to False and vice versa. "If" conditions like this only execute if everything within them evaluates to true, so that's why you flip values that you want to be false to true for testing.

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 ,
Feb 06, 2020 Feb 06, 2020

Copy link to clipboard

Copied

LATEST

(dang dyslexia! more coffee should help)

 

thank you very much clay!- i will run some tests with this 

 

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