Search code examples
javascripteaseljsanimate-cc

Am I using `button.disabled = true;` incorrectly?


I'm trying to build an interaction in Animate CC that plays movie clips, and the buttons disappear after they are clicked.

I'm trying to disable the other buttons temporarily while the movie clip plays over the main background, but it's not playing nice.

A code Snippet of the click handler:

exportRoot.btn_cook.addEventListener("click", cook_clickHandler.bind(this));
function cook_clickHandler(){
    exportRoot.cook.gotoAndPlay(1); //play the info clip
    exportRoot.btn_cook.visible = false; //hide button for no replays
    disableAll();
}

disableAll(); does the following for each button on the canvas:

if(exportRoot.btn_receive.visible == true){
    exportRoot.btn_receive.disabled = true;
}

I'm having some trouble trying to figure out how to use this properly. When I run through the interaction, I am still able to click on the buttons, even though I supposedly disabled them?

This demo won't load sound on GitHub, but it works otherwise. Click here to see it.


Solution

  • I had the same problem so I have another way to do it:

    You can try to remove the eventListener click, like this:

    if(!exportRoot.btn_receive.hasEventListener("click")){
        exportRoot.btn_receive.removeEventListener("click", cook_clickHandler);
    }
    

    When u want this to be enabled again, add the eventListener.