作者:Seet琸琸 | 来源:互联网 | 2023-05-19 18:54
I'll try to be as concise as possible. I have a number of objects in an array, and I'm applying event listeners to each one using closures:
我会尽量简洁。我在数组中有许多对象,我正在使用闭包为每个对象应用事件监听器:
//reduced to the logic in question:
buttons.forEach(function(button:EventDispatcher, i:int, list:Array):void {
button.addEventListener(MouseEvent.MOUSE_OVER, function(e:Event):void {
button.filters = [button_glow_filter];
});
});
//button-specific click handlers:
buttons[0].addEventListener(MouseEvent.MOUSE_CLICK, handle_some_action);
This works perfectly for a while, until I perform an unrelated action on the UI. It's a very complex system, so I'm not really sure what is happening. I can confirm that the unrelated action has no direct effect on the object that contains the buttons or the buttons themselves (at least, it's not changing anything via the public interfaces). The buttons still exist, and the click event listeners still work correctly because those are individually assigned real functions on the class's interface.
这在一段时间内完美运行,直到我在UI上执行不相关的操作。这是一个非常复杂的系统,所以我不确定发生了什么。我可以确认不相关的动作对包含按钮或按钮本身的对象没有直接影响(至少,它不会通过公共接口改变任何东西)。按钮仍然存在,并且单击事件侦听器仍然可以正常工作,因为这些按钮在类的接口上单独分配了实际功能。
My question therefore is: does anyone know what can cause these closures to stop handling the MouseOver events without having any other perceptible effect on the related objects?
因此我的问题是:有没有人知道什么可以导致这些闭包停止处理MouseOver事件而不会对相关对象产生任何其他可察觉的影响?
There are a number of ways to accomplish this MouseOver behavior, and for now I've switched to one that works, but I'd still like to know the answer to this question for future reference.
有很多方法可以实现这种MouseOver行为,现在我已经切换到一个有效的方法,但我仍然想知道这个问题的答案以供将来参考。
1 个解决方案