admin管理员组文章数量:1317565
Does EaselJS's removeChild
method, (part of Stage), handle cleanup of eventListeners attached to that child, as well? Or must you manually remove the child's event listeners using removeEventListener
before removing the child?
For example:
stage = new createjs.Stage(canvas);
circle = new createjs.Shape();
circle.graphics.beginFill("#333").drawCircle(0,0,5);
circle.addEventListener("mousedown",function(event){
console.log("mouse down");
});
stage.addChild(circle);
.
.
.
stage.removeChild(circle);
Does EaselJS's removeChild
method, (part of Stage), handle cleanup of eventListeners attached to that child, as well? Or must you manually remove the child's event listeners using removeEventListener
before removing the child?
For example:
stage = new createjs.Stage(canvas);
circle = new createjs.Shape();
circle.graphics.beginFill("#333").drawCircle(0,0,5);
circle.addEventListener("mousedown",function(event){
console.log("mouse down");
});
stage.addChild(circle);
.
.
.
stage.removeChild(circle);
Share
Improve this question
edited May 25, 2021 at 15:20
Brian Tompsett - 汤莱恩
5,89372 gold badges61 silver badges133 bronze badges
asked Aug 29, 2013 at 15:51
jzweigjzweig
111 silver badge2 bronze badges
1 Answer
Reset to default 8EventListeners are not removed upon removeChild()
, as they are also not added upon addChild()
- If you do want to quickly remove them all, the quickest way would be myChild.removeAllEventListeners();
However if a DisplayObject is not attached to the Stage somehow, events won't be dispatched by mouse-interactions, because those only bubble through the stage and its' children.
In case you worry about memory-leaks: Events in EaselJS are sitting directly on the DisplayObject itself, so whenever you delete the reference to that Object, the Events will(should) be collected by the GarbageCollecter as well, no need for removing events separately. (please, someone correct me here, in case I'm wrong)
本文标签: javascriptDoes EaselJS removeChild also remove attached eventListenersStack Overflow
版权声明:本文标题:javascript - Does EaselJS removeChild also remove attached eventListeners? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742001368a2411078.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论