Skip to main content
Liereman
Known Participant
October 31, 2018
Answered

Adobe Animate Canvas (HTML5) Show-hide object with one button.

  • October 31, 2018
  • 1 reply
  • 5150 views

I use a button (name = Knop) to show an object (name = Afbeelding).

You can see the script below:

this.Afbeelding.visible = false;

this.Knop.addEventListener("click", fl_MouseClickHandler.bind(this));

function fl_MouseClickHandler()
{
{

  this.Afbeelding.visible = true;

}

}

How can I use the same button (Knop) to hide the object (Afbeelding) after showing it?

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

Invert the visibility of a display object using the logical NOT ( ! ) operator. Like this:

function fl_MouseClickHandler()

{

    this.Afbeelding.visible = !this.Afbeelding.visible;

}

this.Afbeelding.visible = false;

this.Knop.addEventListener("click", fl_MouseClickHandler.bind(this));

I hope this helps.

Regards,

Jc

1 reply

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
October 31, 2018

Hi.

Invert the visibility of a display object using the logical NOT ( ! ) operator. Like this:

function fl_MouseClickHandler()

{

    this.Afbeelding.visible = !this.Afbeelding.visible;

}

this.Afbeelding.visible = false;

this.Knop.addEventListener("click", fl_MouseClickHandler.bind(this));

I hope this helps.

Regards,

Jc

Liereman
LieremanAuthor
Known Participant
October 31, 2018

Hi JoãoCésar,

The script you mentioned just works perfect.

Many thanks!!!

JoãoCésar17023019
Community Expert
Community Expert
October 31, 2018

You're welcome!