Skip to main content
Participant
May 4, 2023 8:10 PM UTC
Answered

Making a button visible on a array

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 is closed to new replies. Start a new post to keep the conversation going.
LeonardoVBoniniCorrect answer
Participant
May 5, 2023 8:14 PM UTC

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 8:14 PM UTC

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;

Translate
kglad
Community Expert
Community Expert
May 5, 2023 3:28 PM UTC

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

Translate
Vladin M. Mitov
Inspiring
May 5, 2023 9:12 AM UTC

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.


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