0

Is is possible for two stage objects to contain the same child element?

I am basically looking to create two stages with differing scale factors, each containing all of the same child elements and essentially "mirroring" each other at different scales. Whenever I add a child element to the second stage, it seems to be removed from the first automatically. Is there an option I'm not aware of to allow multiple stages to share and render the same child objects?

itsmequinn
  • 1,054
  • 1
  • 8
  • 21

1 Answers1

1

They can't contain the same children, as you've seen by adding children from one stage to the other.

You may want to clone the main stage and recreate it within the second, or at least the children of the stage.

child = stage.getChildAt(i).clone(true);

See this simple example: http://jsfiddle.net/jAUEv/1/

egaudette
  • 98
  • 7
  • Hey thanks. I knew about cloning, but I am working with animation and was hoping to find a way to make sure both canvas's children's coordinates, rotations, etc were kept automatically synced without having to manage two separate sets of children. – itsmequinn Jan 28 '14 at 19:42
  • Well, you could have one 'control' object that holds transformation values for the children, and apply the same transformations to children of both canvases. I'm guessing that the children of a given canvas may differ in their transformations, and that there couldn't be one global object to hold this. You may want to make a transformation matrix for each child, store it within the child, and apply it when cloning the child to the second stage. – egaudette Jan 28 '14 at 21:25