Function to automate buttons

70 views Asked by At

I have to do this code 103 times, but I can't create a function so I don't have to write it for each of the buttons (working with animate-cc + createjs).

this.Box1.addEventListener("click", click1.bind(this));

function click1() {
    this.parent.nombres.gotoAndStop(1);
}

this.Box2.addEventListener("click", click2.bind(this));

function click2() {
    this.parent.nombres.gotoAndStop(2);
}

this.Box3.addEventListener("click", click3.bind(this));

function click3() {
    this.parent.nombres.gotoAndStop(3);
}

I appreciate your help in advance.

1

There are 1 answers

0
V-Jake On

You can put that in an array and then put it in a for or while loop.

I had the same problem. My scripting is to rusty so I do not know how to write the script exactly.

var buttons:Array = new Array(bnt1,bnt2,bnt3,bnt4,bnt5);

But even that can be simplefied.