Skip to main content
Inspiring
February 5, 2014
Answered

TextField won't display if parent is a child?

  • February 5, 2014
  • 1 reply
  • 517 views

Hi!

I'm writing a new framework but I've encountered an odd bug. Whenever I add a class as a child to my main sprite, it doesn't display the class's TextField. Only if I add it as a child of the stage will it display.

Main.as (Highlighted as Java)

spirea = new World(this.stage);

                                spirea.addChild(new LoginForm(spirea));

LoginForm.as

public class LoginForm extends Sprite

          {

                    public var usernameField:TextField;

                    public var passwordField:TextField;

                    public function LoginForm(w:World)

                    {

                              usernameField = new TextField;

                              usernameField.x = 200;

                              usernameField.y = 50;

                              usernameField.width = 200;

                              usernameField.height = 35;

                              usernameField.border = true;

                              usernameField.borderColor = 0x000000;

                              usernameField.type = TextFieldType.INPUT;

                              addChild(usernameField);

                    }

          }

World is an extention of Sprite with a shaded bitmap added to it for decoration. It's a constant throughout the game, as in it doesn't disappear. The present code doesn't work. If I don't make it a child of spirea, it will work just fine. However, if I do w.addChild(usernameField); in LoginForm.as, it doesn't work. Neither does a combination of spirea.addChild(new LoginForm(spirea)); in Main.as and w.addChild(usernameField);

Is this just the nature of TextField or am I doing something very wrong?   

This topic has been closed for replies.
Correct answer sinious

Yes you must add spirea to the display list so its children can be seen.

1 reply

sinious
siniousCorrect answer
Legend
February 5, 2014

Yes you must add spirea to the display list so its children can be seen.

Inspiring
February 6, 2014

Ah I removed that line! Gah that should have been obvious..

sinious
Legend
February 6, 2014

We all look at the same code too long and just go blind, happens all the time . Good luck!