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
--
here is what i have that works great for me so far:
again thanks in advance!
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
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!!
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.
Copy link to clipboard
Copied
(dang dyslexia! more coffee should help)
thank you very much clay!- i will run some tests with this