Copy link to clipboard
Copied
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?
Yes you must add spirea to the display list so its children can be seen.
Copy link to clipboard
Copied
Yes you must add spirea to the display list so its children can be seen.
Copy link to clipboard
Copied
Ah I removed that line! Gah that should have been obvious..
Copy link to clipboard
Copied
We all look at the same code too long and just go blind, happens all the time . Good luck!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now