Bring to front & send to back help

I have been working on a custom clone system and I have been looking for a way to be able to move the objects back and forth between each other. I was looking at this post that showed how to move clips back and forth but I am wondering if there might be some way to have it work with the objects that I am using which aren’t clips, although the objects that I am using also work in a odd way related to the hierarchy of the project which might also be an issue. I tried using paper.js send to back and bring to front functions but they don’t actually do anything.
CustomObjClone11-13-2021_13-12-58.wick (2.1 KB)

1 Like

In the ideal world… We should formally work together and put a custom wick editor with new features.
I’m kind of doing it for fun in my free time (unfortunately is not much time…)

@SomeoneElse
Every clip belongs to a frame… so your clip is a child of it. You can access it parent frame by clip.parentFrame. Since a its parentFrame can contain more than one clip, it has a property called _children, which returns an array of all its children. This array is used by the Editor to display all the clips, within that Frame, in that order.

Here is a great example from @pumpkinhead

Wick.Clip.prototype.sendToBack = function() {
    var siblings = this.parentFrame._children;
    var index = siblings.indexOf(this);
    
    siblings.splice(index, 1);
    siblings.unshift(this);
};

Wick.Clip.prototype.sendToFront = function() {
    var siblings = this.parentFrame._children;
    var index = siblings.indexOf(this);
    
    siblings.splice(index, 1);
    siblings.push(this);
};

Wick.Clip.prototype.sendForward = function(num) {
    var siblings = this.parentFrame._children;
    var index = siblings.indexOf(this);
    
    var newIndex = index + num;
    if (newIndex >= siblings.length) newIndex = siblings.length - 1;
    if (newIndex < 0) newIndex = 0;
    
    siblings.splice(index, 1);
    siblings.splice(newIndex, 0, this);
};

I did a quick test to see if the cloned objects appear in the frame’s children but the issue is that the clone thing is weird. If I console.log(this) in the frame’s script before the objects are added with the custom clone, there is one child which is supposed to be there. Then when I do it after the objects are created it still says there’s only the 1 object still. I think that the cloned objects don’t actually match up with the frame exactly because if I look at the parent of the returned object after breaking the clip apart it also doesn’t have a parent. Although for some reason they still appear in the outliner.

So I still don’t fully understand what happens to the cloned clips when they are broken apart