I have 3 movieclips and each has a textbox as a child.
I set the active one with
var myroot:MovieClip = this.root as MovieClip;
var activeText:MovieClip;
This works
function keyClicked (e:MouseEvent) {
myroot.firstname_mc.getChildAt(0).text += "hello";
}
This does not
function keyClicked (e:MouseEvent) {
activeText.getChildAt(0).text += "hello";
}
How can I get this to work dynamically?
Your whole problem is that you’re trying to do things that you shouldn’t do. What you should do instead is write Classes that encapsulate the desired behavior, and let them handle the details. For example:
Now, in your main Document Class, you type activeText as Label, and you can then set its text like this:
And you can now reuse the new Class you wrote to make all sorts of different-looking Labels, just as long as each contains a TextField called tf.