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

Making a button visible on a array

New Here ,
May 04, 2023 May 04, 2023

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;
   }
}

TOPICS
Code , How to , Other
406
Translate
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

correct answers 1 Correct answer

New Here , May 05, 2023 May 05, 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;

Translate
Engaged ,
May 05, 2023 May 05, 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 1998
Member of Flanimate Power Tools team - extensions for character animation
Translate
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 ,
May 05, 2023 May 05, 2023

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

Translate
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 ,
May 05, 2023 May 05, 2023
LATEST

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
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