Using 'on' and 'off' with respect to 'addEventListener' and 'removeEventListener'
Hi,
I can’t seem to get on and off working in respect of addEventListener and removeEventListener.
Here is my simple code as example:
var me = this;
this.btn1.on("click", btn1Click);
this.btn1.on("mouseover", btn1Over);
this.btn1.on("mouseout", btn1Out);
function btn1Click(){
removeEvents();
//code does other stuff
}
function btn1Over(){
// code for over state
}
function btn1Out(){
//code to resume button to normal state
}
function removeEvents(){
me.btn1.off("mouseout", btn1Out);
}
The off does not work in the removeEvents() function. But when I try the code…
var me = this;
this.btn1.addEventListener("click", btn1Click);
this.btn1.addEventListener("mouseover", btn1Over);
this.btn1.addEventListener("mouseout", btn1Out);
function btn1Click(){
removeEvents();
//code does other stuff
}
function btn1Over(){
// code for over state
}
function btn1Out(){
//code to resume button to normal state
}
function removeEvents(){
me.btn1.removeEventListener("mouseout", btn1Out);
}
This works! I’d like to know how I am using on and off in place of addEventListener and removeEventListener incorrectly?
I have looked and tried to understand the instructions on the CreateJS site but as I am not a strong programmer it is going over my head.
Cheers!
