Skip to main content
Participating Frequently
June 14, 2013
Answered

What is the easiest way to removechild a hoarde of components made with AS3?

  • June 14, 2013
  • 1 reply
  • 993 views

I tried sprite and now movieclip to try and get around the fact that Flash doesn't allow you to addchild to scenes as common sense as that would seem to be

because I am making a dynamic form that has multiple components for each person in a group that are produced from a previous scenes group number text field.

After some hair pulling got that working only to be dismayed when adding a back button to previous scene (form) to find all the the previous scene/form components still on the scene.  I

would rather not have to remove every single component when the back button is pushed so I was hoping to put them in a container that I could either make invisible or

just removechild the container.  I tried both sprite and movieclip but not understanding how they work.

This is a test with movieclip but it doesn't show anything on the screen when run.

import flash.display.MovieClip;

var container1:MovieClip = new MovieClip(); 

container1.x = 1;

container1.y = 1;

container1.width = 400;

container1.height = 400;

container1.visible = true;

container1.opaqueBackground = 0xFF0000;

container1.border = true;

var tf2:TextField = new TextField();

tf2.border = true;

tf2.text = "text 2";

tf2.textColor = 0xFF0000;

tf2.x = 2;

tf2.y = 2;

tf2.width = 150;

tf2.height = 32;

container1.addChild(tf2);

stage.addChild(container1);

stop();

This topic has been closed for replies.
Correct answer Ned Murphy

Removing a hoard of objects is not difficult.  If you place them inside a container then you can use a loop and container.removeChildAt(0) until there are no children left.  You do not have to code each one separately.

When you add content dynamically it does not have a home on the timeline - unless you load it into something that was not created dynamically, such as an empty movieclip that you manually place on the stage.  So if you wanted to go back a frame or so and leave things behind, then have a manually placed container in that frame so that it stays where it was planted.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
June 14, 2013

Removing a hoard of objects is not difficult.  If you place them inside a container then you can use a loop and container.removeChildAt(0) until there are no children left.  You do not have to code each one separately.

When you add content dynamically it does not have a home on the timeline - unless you load it into something that was not created dynamically, such as an empty movieclip that you manually place on the stage.  So if you wanted to go back a frame or so and leave things behind, then have a manually placed container in that frame so that it stays where it was planted.

Participating Frequently
June 14, 2013

I am assuming if a TextInput is removechild the value the person entered is gone.  I was going to have back/forward buttons on each scene/form and would like the

information to stay when they come back.  At some point I got to load it to variables but that would be complicated at this stage to pull in the variables when addchilding the components back.

I like the empty movieclip idea.  That would seem to preserve everything in limbo while keeping it tied to the scene (or at least Flash dealing with the add/removing it in the background)

so it seems that way to me.

Hmm, wondering if I can call the movieclips named scene1, scene2, etc so I can have scene1.addChild(name);

Participating Frequently
June 14, 2013

Well bleep!

Using a blank movieclip for each scene is working as I would expect going from scene/form/movieclip to scene/form/movieclip without any stow-away components, but it

isn't keeping the values the user enter's into the text boxes as I was hoping it might.