Saturday, September 8, 2007

move child from one parent to another - as3

saw it on Flashcoders,Greetz Erik reply "Copy and paste a movieClip?"
here is quote from him:

Yes in AS3 you can move DisplayObjects to other parents without problems.
One thing to note is that you need to remove it from the current display
list before you add it to the other.

Something like this:

parent1.removeChild(theClip);
parent2.addChild(theClip);

i didn't know it, i will give it a try

1 comment:

bob said...

this only works if you don't have any variables declared inside the clip from outside. so if you're figuring out variables outside and passing them into the clip to be stored and be used - let's say if you're adding multiple instances of the same child and you want each of them to have a different behavior that might carry through if and when you decide you want to move them somewhere else. then you have to clone the existing clip and all its variables before removing and adding, it's not as simple as remove/add.