PDA

View Full Version : Child Parent AHHHHHH



gargantus
April 25th, 2008, 06:20 PM
Hey there guys,
addChild is handy in a lot of ways but has (for me) made some of the simple things harder.
My problem is loading a movieclip in a container and then replacing it with another.
in as2 you would just attachMovieClip on the container and it replaces the last clip.
If i do it in as3 it just adds it to the stack is there an easy way round this anyone that i am missing? so i can easily load a clip and remove whatever is in the container.


Cheers for your help...:-)

senocular
April 25th, 2008, 06:24 PM
while(container.numChildren) container.removeChildAt(0);
container.addChild(newContent);

?

gargantus
April 25th, 2008, 06:35 PM
hahaha Thanks senocular for that just as you posted i sussed it with a similair thing. (always the way)

if (container.numChildren >0) {
container.removeChildAt(0);
}
container.addChild(newClip);

cheers for your reply yours works too nice! is much more useful once you get rid of the as2 way of thinking. ;-)

magcius
April 25th, 2008, 07:45 PM
You want to use a while loop, not an if loop.

Otherwise, you'll only get the first child removed.