0
Engaged
,
/t5/animate-discussions/html5-canvas-detect-button-state/td-p/12818487
Mar 16, 2022
Mar 16, 2022
Copy link to clipboard
Copied
I thought this would be simple.
I just want to have a toggle button, so that when clicked, its state stays in the downState, and when clicked again, it goes to the upState. For that to work I would need to know what state the button is in.
This works to the point the button stays in the downStte if clicked, but it's not working for toggling back to the upstate:
this.retinoscopeButton.addEventListener("click", retinoscope.bind(this));
function retinoscope(){
if (retinoscopeButton.upState == true){
retinoscopeButton.upState=retinoscopeButton.downState;
} else if (retinoscopeButton.downState == true){
retinoscopeButton.downState=retinoscopeButton.upState;
}
}
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
1 Correct answer
Engaged
,
Mar 16, 2022
Mar 16, 2022
This works for me...
var toggle;
if (!root.retinoscopeButton.hasEventListener("click")) {
toggle = false;
root.retinoscopeButton.addEventListener("click", retinoscopeButtonClickHandler.bind(this));
}
root.retinoscopeButton.addEventListener("mouseover", retinoscopeButtonRollOverHandler.bind(this));
root.retinoscopeButton.addEventListener("mouseout", retinoscopeButtonRollOutHandler.bind(this));
function retinoscopeButtonClickHandler() {
if (toggle == false) {
root.retinoscopeButton.gotoA
...
FlatChat
AUTHOR
Engaged
,
/t5/animate-discussions/html5-canvas-detect-button-state/m-p/12818518#M352503
Mar 16, 2022
Mar 16, 2022
Copy link to clipboard
Copied
and I have tried these:
this.retinoscopeButton.addEventListener("click", retinoscope.bind(this));
/*function retinoscope(evt) {
var retinoscopeButtonState = evt.currentTarget.state = !evt.currentTarget.state;
if (retinoscopeButtonState) {
this.retinoscopeButton.upState = this.retinoscopeButton.downState;
} else {
this.retinoscopeButton.downState = this.retinoscopeButton.upState;
}
}*/
var retinoscopeButtonState = 'up';
function retinoscope(evt){
if (retinoscopeButtonState == 'up'){
root.retinoscopeButton.upState = root.retinoscopeButton.downState;
retinoscopeButtonState = 'down';
} else if (retinoscopeButtonState == 'down'){
root.retinoscopeButton.downState = root.retinoscopeButton.upState;
retinoscopeButtonState = 'up';
}
}
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
FlatChat
AUTHOR
Engaged
,
/t5/animate-discussions/html5-canvas-detect-button-state/m-p/12818625#M352505
Mar 16, 2022
Mar 16, 2022
Copy link to clipboard
Copied
also the following which works to turn 'on' the button, but not to turn 'off'. This is using the button as a MovieClip...
if(!root.retinoscopeButton.hasEventListener("click")){
this.toggle = false;
root.retinoscopeButton.addEventListener("click", retinoscopeButtonClickHandler.bind(this));
}
//root.retinoscopeButton.addEventListener("click", retinoscopeButtonClickHandler.bind(this));
//root.retinoscopeButton.addEventListener("mouseover", retinoscopeButtonRollOverHandler.bind(this));
//root.retinoscopeButton.addEventListener("mouseout", retinoscopeButtonRollOutHandler.bind(this));
function retinoscopeButtonClickHandler() {
if(this.toggle == false){
root.retinoscopeButton.gotoAndStop(2);
} else if(this.toggle == true){
root.retinoscopeButton.gotoAndStop(0);
}
}
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Engaged
,
LATEST
/t5/animate-discussions/html5-canvas-detect-button-state/m-p/12818636#M352506
Mar 16, 2022
Mar 16, 2022
Copy link to clipboard
Copied
This works for me...
var toggle;
if (!root.retinoscopeButton.hasEventListener("click")) {
toggle = false;
root.retinoscopeButton.addEventListener("click", retinoscopeButtonClickHandler.bind(this));
}
root.retinoscopeButton.addEventListener("mouseover", retinoscopeButtonRollOverHandler.bind(this));
root.retinoscopeButton.addEventListener("mouseout", retinoscopeButtonRollOutHandler.bind(this));
function retinoscopeButtonClickHandler() {
if (toggle == false) {
root.retinoscopeButton.gotoAndStop(2);
toggle = true;
} else if (toggle == true) {
root.retinoscopeButton.gotoAndStop(0);
toggle = false
}
}
function retinoscopeButtonRollOverHandler() {
if (toggle == false) {
root.retinoscopeButton.gotoAndStop(1);
}
}
function retinoscopeButtonRollOutHandler() {
if (toggle == false) {
root.retinoscopeButton.gotoAndStop(0);
}
}
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

