JavaScript button in Animate CC

0

Good afternoon guys,

I'm developing a screen in Animate CC, the screen is 12 buttons and when the user "clicks" on all and at the end of the counter performs the function to unlock the screen.

What is happening, is that if it clicked on only 1 button 12 times release the function, I need to make the button only add once when "clicked."

Thank you !!

Code:

var contador = 0;

function verificaAvanco() {

  contador = contador + 1;
  if (contador == 12)
    window.parent.postMessage('destravaSlide', '*');
}

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

function fl_MouseClickHandler() {
  this.gotoAndStop('f1');
  verificaAvanco();
}

this.b2.addEventListener("click", fl_MouseClickHandler_2.bind(this));

function fl_MouseClickHandler_2() {
  this.gotoAndStop('f2');
  verificaAvanco();
}

this.b3.addEventListener("click", fl_MouseClickHandler_3.bind(this));

function fl_MouseClickHandler_3() {
  this.gotoAndStop('f3');
  verificaAvanco();
}

this.b4.addEventListener("click", fl_MouseClickHandler_4.bind(this));

function fl_MouseClickHandler_4() {
  this.gotoAndStop('f4');
  verificaAvanco();
}

this.b5.addEventListener("click", fl_MouseClickHandler_5.bind(this));

function fl_MouseClickHandler_5() {
  this.gotoAndStop('f5');
  verificaAvanco();
}

this.b6.addEventListener("click", fl_MouseClickHandler_6.bind(this));

function fl_MouseClickHandler_6() {
  this.gotoAndStop('f6');
  verificaAvanco();
}

this.b7.addEventListener("click", fl_MouseClickHandler_7.bind(this));

function fl_MouseClickHandler_7() {
  this.gotoAndStop('f7');
  verificaAvanco();
}

this.b8.addEventListener("click", fl_MouseClickHandler_8.bind(this));

function fl_MouseClickHandler_8() {
  this.gotoAndStop('f8');
  verificaAvanco();
}

this.b9.addEventListener("click", fl_MouseClickHandler_9.bind(this));

function fl_MouseClickHandler_9() {
  this.gotoAndStop('f9');
  verificaAvanco();
}

this.b10.addEventListener("click", fl_MouseClickHandler_10.bind(this));

function fl_MouseClickHandler_10() {
  this.gotoAndStop('f10');
  verificaAvanco();
}

this.b11.addEventListener("click", fl_MouseClickHandler_11.bind(this));

function fl_MouseClickHandler_11() {
  this.gotoAndStop('f11');
  verificaAvanco();
}

this.b12.addEventListener("click", fl_MouseClickHandler_12.bind(this));

function fl_MouseClickHandler_12() {
  this.gotoAndStop('f12');
  verificaAvanco();
}
    
asked by anonymous 14.03.2018 / 17:00

1 answer

1

Speak, Friend,

I believe you can do the validation differently.

Currently your validation is being done through the contactor, so you do not have control of the clicked button, right?

What you can do is create a VAR of type Array with 12 positions and with each clicked button you add the value in the respective position.

var nome_Array = new Array(12);

function verificaAvanco() {


  if (nome_Array.toString() == '1,1,1,1,1,1,1,1,1,1,1,1'){

    window.parent.postMessage('destravaSlide', '*');
}

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

function fl_MouseClickHandler() {

  btn = Number(this.name.slice(1,this.name.length));
  nome_Array[btn-1]= '1'; 

  this.gotoAndStop('f1');

  verificaAvanco();

}

It will get a little manual, but it supplies what you need. Other ways to do it, but based on your code, I think it will help.

    
10.09.2018 / 15:43