Skip to main content
Participating Frequently
June 14, 2013
Resuelto

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

  • June 14, 2013
  • 1 respuesta
  • 993 visualizaciones

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();

Este tema ha sido cerrado para respuestas.
Mejor respuesta de 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 respuesta

Ned Murphy
Ned MurphyRespuesta
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

My own approach to this would be to just use movieclips in place of each scene, and have them all in one frame of one scene.  Then you just have to control their visibility and anything that was entered into them will definitely remain since you are not moving away.

Otherwise, if you want things in different frames/scenes (I recommend against using scenes in any coded design), and you want things to retain their data, then you need to store that data and rewrite it each time you enter that frame/scene.


This is neverending.  I can not figure out how to pass variables from main timeline to each movies timeline.  Nor the instance names of the movieclips either.

I named each movieclip menu1, menu2, etc. , but I try changing the visiblities on button click like

menu1.visible = false;

menu2.visible = true;

and it gets compiler errors that property is not defined for menu1.  I get the same error from trying to use variables in movie clip that

I defined on main timeline.