Animate/EaselJS - removeEventListener 不工作

Animate / EaselJS - removeEventListener not working

我对 Adob​​e Animate CC 及其使用的 Javascript 框架有疑问,EaselJS/CreateJS。我可以添加事件侦听器 w/o 问题,但我无法删除它们。我从调试器中尝试了各种方法,包括进入他们的 JS removeEventListener 处理程序 - 虽然这两个变量看起来相同,但它们永远不会 ==(或 ===),所以不会删除偶数侦听器。

这是我使用的代码,它的目的是在将鼠标悬停在某个元素上时淡入:

this.fadeIn = function(target_mc)
    {
        target_mc.alpha = 0;
        target_mc.visible = true;

        target_mc.removeEventListener("tick",fadeIn_onEnterFrame);
        target_mc.addEventListener("tick",fadeIn_onEnterFrame.bind(this));

        function fadeIn_onEnterFrame(evt)
        {
            evt.currentTarget.alpha = evt.currentTarget.alpha + .2;
            if (evt.currentTarget.alpha >= 1)
            {
                evt.currentTarget.removeEventListener("tick",fadeIn_onEnterFrame);
            } // end if
        }
    } // End of the function

所以你知道,它被添加到 frame_0 中的 Canvas,并从添加到每种服装类型的 "mouseover" 侦听器调用(它用于拖放 - drop dress-up game, FWIW)

function clothing_onRollOver()
{
    this.hint_mc.desc_mc.desc1_txt.text = this.articleName;
    this.fadeIn(this.hint_mc);
    this.clothingOver = true;
};
clothing.addEventListener("mouseover",clothing_onRollOver.bind(this));

您的代码似乎存在一些范围界定问题。下面的代码片段修复了您的问题并正确删除了事件侦听器,但是我不知道为什么您当前的实现无法正常工作。

不同之处在于我已经从 target_mc.addEventListener("tick",fadeIn_onEnterFrame.bind(this));

中删除了绑定

但是我不确定 .bind() 导致此问题的原因。

stage.enableMouseOver();

clothingOver = false;

this.hint_mc.visible = false;

this.fadeIn = function(target_mc)
{
    console.log(target_mc);

    target_mc.alpha = 0;
    target_mc.visible = true;

    target_mc.removeEventListener("tick",fadeIn_onEnterFrame);
    target_mc.addEventListener("tick",fadeIn_onEnterFrame);

    function fadeIn_onEnterFrame(evt)
    {
        console.log("tick");
        evt.currentTarget.alpha = evt.currentTarget.alpha + .2;

        if (evt.currentTarget.alpha >= 1)
        {
            evt.currentTarget.removeEventListener("tick", fadeIn_onEnterFrame);
        } // end if
    }
} // End of the function



function clothing_onRollOver()
{
    //this.hint_mc.desc_mc.desc1_txt.text = this.articleName;
    this.fadeIn(this.hint_mc);
    this.clothingOver = true;
};


this.clothing.addEventListener("mouseover",clothing_onRollOver.bind(this));

抱歉,我无法为您确定确切的根本原因。