Copy link to clipboard
Copied
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();
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 h
...Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
If you get errors you should include the errors in your posting.
That code you show should work if you are assigning those instance names to the movieclips on the stage. Instance names are assigned by selecting the object and assigning its name in the Properties panel where it says "<Instance name>"
Copy link to clipboard
Copied
I got the instance name reference going by adding
var top:MovieClip = MovieClip(root);
to each movie and then top.menu2.visible = true; would work from inside the movieclip
That also worked for accessing variables but I ended up needing to add event listeners to
moniter the fields that change the fields in the other movies which seems to make moving textfield values
to variables pointless at this time.
Everything is going good. Values stay when moving back and forth through the form/movieclips, which
turned out to be a problem, bringing back to the original reason for doing this.
If they go back and reduce the number of people in a group, I still need to add code to removechild the extra components when they come back to that page or
if they increase the number to just add the extra fields.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now