Animate CC Canvas 调用函数

AnimateCC Canvas calling functions

我正在尝试将我从 actionscript 3 编写的代码更改为 html5 canvas。我对调用我创建的函数有疑问,例如:

function cleanSelection(){
    this.a1.visible = true;
    this.sa1.visible = false;

    this.a2.visible = true;
    this.sa2.visible = false;
}

function maxSelection(count){
    cleanSelection();
    count = 0;
    return count;
}

我想让下面的函数能够调用 maxSelection(),后者调用 cleanSelection()

this.a1.addEventListener("click", fl_Click.bind(this));
function fl_Click()
{
   this.sa1.visible = true;
   this.a1.visible = false;
   count++;
   if(count >= 2){
       count = maxSelection(count);
   }
}

如何调用这些函数?

您应该在所有方法中放入 "bind(this)":

function cleanSelection(){
   this.a1.visible = true;
   this.sa1.visible = false;

   this.a2.visible = true;
   this.sa2.visible = false;
}

function maxSelection(c){
   cleanSelection.bind(this)();
   c= 0;
   return c;
}
var count = 0;
this.a1.addEventListener("click", fl_Click.bind(this));
function fl_Click() {
  this.sa1.visible = true;
  this.a1.visible = false;
  count++;
  if(count >= 2){
     count = maxSelection.bind(this)(count);
  }

}