-1

我正在尝试在 Animate CC 中构建一个播放影片剪辑的交互,并且按钮在单击后消失。

当影片剪辑在主背景上播放时,我试图暂时禁用其他按钮,但播放效果不佳。

点击处理程序的代码片段:

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();对画布上的每个按钮执行以下操作:

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

我在试图弄清楚如何正确使用它时遇到了一些麻烦。当我完成交互时,我仍然可以点击按钮,即使我应该禁用它们?

这个演示不会在 GitHub 上加载声音,但它可以正常工作。点击此处查看。

4

2 回答 2

1

我遇到了同样的问题,所以我有另一种方法:

您可以尝试删除eventListener click,如下所示:

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

当您希望再次启用此功能时,添加eventListener.

于 2016-12-02T19:11:21.193 回答
1

disabled 属性是一个布尔属性。这意味着它的存在足以导致元素被禁用。您将值设置为什么没有区别。您需要从元素中删除该属性以删除禁用的效果。

删除事件侦听器可以解决问题,它并没有触及问题的核心。

此外(仅供参考),该visibility属性的值是"visible"or "hidden",不是trueor false

以下是如何应用和禁用(没有双关语)禁用属性的简单示例:

btnToggle.addEventListener("click", function(){

  var elems = document.querySelectorAll(".disableEnable");
  
  // Loop through each element in the class
  elems.forEach(function(element){
    
    // Check to see if the first element has the disabled attribute
    // the value of the attribute doesn't matter. If the attribute
    // is present, the element is currently disabled.
    if(element.getAttribute("disabled")){
      
      // Element is disabled, so enabled it by removing
      // the attribute (not by setting a value)
      element.removeAttribute("disabled");
    } else {
      // Element is enabled, so disable it by adding the disabled
      // attribute. Again, the value doesn't matter, but convention
      // says that we set a value of "disabled" to convey that it is
      // a boolean attribute.
      element.setAttribute("disabled", "disabled");
    }
                           
  });
    
});
<button id="btnToggle">Disable / Enable</button>

<button class="disableEnable">Test Button</button>
<input class="disableEnable">
<input type="text" class="disableEnable">

于 2016-12-02T19:20:28.283 回答