Skip to main content
Participant
May 4, 2023
Answered

Making a button visible on a array

  • May 4, 2023
  • 3 replies
  • 459 views

I want to make an array of buttons, and depending on what button was clicked, to sned and variable to the function and make stuff appear visible or invisible. I dont know how to say but heres the code:

var ClickCount = 0;

var BG_Aberto = false;

var Item1_Coletado = false;
var BTN_Coletar = [this.BTN_Coletar_Item1];
var BTN_Devolver = [this.BTN_Devolver_Item1];
var BTN_Item = [this.Item1];
var BG_Item = [this.BG_Item1];

var Item_Coletado = [this.Item1_Coletado];

this.Item1.addEventListener("click", clicarItem(i).bind(this));
this.BTN_Coletar_Item1.visible = false;
this.BTN_Devolver_Item1.visible = false;
this.BG_Item1.visible = false;

function clicarItem(i)
{
   ClickCount++;
   if (this[BG_Item[i]].visible == false){
      this[BG_Item[i]].visible = true;
      if(Item_Coletado[i]==false){
         this[BTN_Coletar[i]].visible = true;
         this[BTN_Devolver[i]].visible = false;
      } else {
         this[BTN_Coletar[i]].visible = false;
         this[BTN_Devolver[i]].visible = true;
      }
   } else {
      BG_Aberto = false;
      this[BG_Item[i]].visible = false;
      this[BTN_Coletar[i]].visible = false;
      this[BTN_Devolver[i]].visible = false;
   }
}

This topic has been closed for replies.
Correct answer LeonardoVBonini

I found the problem!
this.Item1.addEventListener("click", clicarItem(i).bind(this));
this is the problem. If anyone have the same problem you need to write like this:
this.Item1.addEventListener("click", clicarItem.bind(this, variable of the function*));
and this:
this.[BG_Item[i]].visible = true;
turn into this:
BG_Item[i].visible = true;

3 replies

LeonardoVBoniniAuthorCorrect answer
Participant
May 5, 2023

I found the problem!
this.Item1.addEventListener("click", clicarItem(i).bind(this));
this is the problem. If anyone have the same problem you need to write like this:
this.Item1.addEventListener("click", clicarItem.bind(this, variable of the function*));
and this:
this.[BG_Item[i]].visible = true;
turn into this:
BG_Item[i].visible = true;

kglad
Community Expert
Community Expert
May 5, 2023

that code has so many problems it almost certainly needs to be redone in its entirety.

Vladin M. Mitov
Inspiring
May 5, 2023

Hi,
In order for us to assist you, it might be better if you could explain what you are trying to achieve with your code.


- Vlad: UX and graphic design, Flash user since 1998Member of Flanimate Power Tools team - extensions for character animation