Skip to main content
Participating Frequently
March 21, 2009
Question

How come I can't add a textField to a Movie Clip dynamically?

  • March 21, 2009
  • 2 replies
  • 394 views
I've got a MovieClip on the MainTimeline: mc_back

I want to dynamcially add textfields to it:

txt:TextField = new TextField();
txt.Height = 20;
txt.Width = 60;
txt.text = 'This is Some Text'

mc_back.addChild(txt);

It's not working. No errors, no nothing, but the textFields don't show up when I run it.
This topic has been closed for replies.

2 replies

Inspiring
March 21, 2009
Not sure whether this is the exact code you use, but:

it would have to be:

var txt:TextField = new TextField();

and all properties have a lowercase char as their first.

I would expect errors from your code though...

Bortiquai wrote:
> I've got a MovieClip on the MainTimeline: mc_back
>
> I want to dynamcially add textfields to it:
>
> txt:TextField = new TextField();
> txt.Height = 20;
> txt.Width = 60;
> txt.text = 'This is Some Text'
>
> mc_back.addChild(txt);
>
> It's not working. No errors, no nothing, but the textFields don't show up when
> I run it.
>
BortiquaiAuthor
Participating Frequently
March 21, 2009
Thanks for the replies.

That was not the exact code - I know... not a good way to ask a question. I found that with the code I have I was able to add the text field to this.addChild(txt), but when I tried to add it to this.mc_back(txt) it would not work.

Then I found that it actually was adding the child, I just couldn't see it. Part of the code is to increase the height of the movie clip then add the text field so it "grows" as text fields are added. What I'm finding is that it is scaling the movie clip, not just increasing it's dimensions, so by the time I add a few objects (and increase the MC height each time) it looks like it is really zoomed in. Is there a way to just increase the size of the movie clip without this zooming in?

Thanks
March 21, 2009
Hey Bortiquai,

Make sure you are importing the right classes. In your situation, make sure you have:

import flash.text.*;

See if this works.

Thanks.