Moving node from group to layer cause the node not to trigger events
I've experienced this on 4.0.2 and on the newest version on git.
When : a) Create layer1 and a group1 and add it to stage, create rect1 and attach it to the group1. b) remove a rect1 from a group1 and attach it to layer1
Problem:
- The node doesn't receive the events is registered for.after step b)
Here is an example: http://jsfiddle.net/fram/zDtgL/ The green box as handlers attached that change the pointers Clicking the red box switches the green rect from the group to the layer and the event do not trigger anymore.
The above test case was working fine on version 4.0.0 http://jsfiddle.net/fram/4LQX2/
I have noticed this before. The reason is that the remove command removes the nodes colorkey from the stage, and that's why it can trigger events. You can manually insert the color key in the stage's list. I've done this but don't remember the code right now, but it shouldn't be to har to figure out. I saw one workaround: instead of adding the node after it's removed, add a clone of the node. The clone will have a new colorkey.
Finally I would suggest to Eric to solve this by re-adding the remove to containers, but don't let it remove the colorkey and instead have a .destroy() on the node (that removes the node, the colorkey and maybe unsets other values). This way the add/remove analogue would remain intact.
Thanks for your reply. So you're saying that the semantic of remove is currently to destroy the node. So probably I should be using the node method moveTo instead of removing and adding the node. If this is the case the issue can be closed just by adding a comment under the remove method that clarifies the behavior and reference moveTo.
Yes, the move to would do what you need. But i've seen some cases where a developer wants to have an undo-method for deleting object, and then there are no way to first remove it from an object, and then put it back without using remove(), so i still think it's a bit of a problem.
And since the colorkey of the object is created when the object is created (and not added to the stage) it shouldn't really be deleted when you do a remove. This is still not expected, i would say. But probably not very high priority either...
Interesting stuff. We can leave this issue open so that I can come back to it later
Following up with this thread - This is no longer an issue because remove() now removes a Node from the node tree without destroying it as of v4.3.1:
https://github.com/ericdrowell/KineticJS/wiki/Change-Log
to destroy a node, you now use destroy();