检测舞台上的 mouseUp

发布于 2024-08-20 03:08:06 字数 291 浏览 2 评论 0原文

有没有办法检查已附加到舞台的方法?

我的舞台是全局的..并且需要在 mouseup 上的对象中触发一些功能... 现在它会触发 2 或 3 个,具体取决于我添加的对象数量。

我需要类似的东西。

if($.stage.hasEventListener(MouseEvent.MOUSE_UP, this.mouseUp) === false){ $.stage.addEventListener(MouseEvent.MOUSE_UP, this.mouseUp); 或者

有更好的方法来处理这个问题?

Is there a way to check the method that has been attached to the stage?

I have stage as global.. and need to fire some function in a object on mouseup...
Now it fires 2 or 3 depending how many objects i add..

I need something like..

if($.stage.hasEventListener(MouseEvent.MOUSE_UP, this.mouseUp) === false){
$.stage.addEventListener(MouseEvent.MOUSE_UP, this.mouseUp);
}

Or a better way to handle this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初懵 2024-08-27 03:08:06

我猜您正在每个对象中添加侦听器,不是吗?这意味着每次创建对象的实例时,您都会为舞台鼠标释放事件添加另一个侦听器。如果您确实只需要此类事件的单个侦听器,请将其移到对象范围之外,并且仅添加侦听器一次。祝你好运!

I'm guessing you are adding the listener inside each object, no? That means every time you create an instance of your object you are adding yet another listener for stage mouse up events. If you really only want a single listener for this type of event, move it outside of the scope of the object and only add the listener once. Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文