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;
}
}
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
...
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';
}
}
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);
}
}
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);
}
}