0
votes

I am trying to get a textfield onto my stage and I have worked out the following code. It seems to have no errors, but it is not appearing in the frame I put the code.

I am very new to this, so I am not sure if I can add a textfield just by using action script 3.

Am I missing anything crucial or am I seeing this the completely wrong way??

stop();

 import fl.text.TLFTextField;
 import flash.text.TextFormat;

 //formatLoginScreenText = flst
 var flst:TextFormat = new TextFormat();
 flst.font = "Verdana";
 flst.size = 20;
 flst.align = TextFieldAutoSize.CENTER;

 //The Actual TextFields
 var usernameField:TLFTextField = new TLFTextField();
 usernameField.x = 208.05;
 usernameField.y = 209;
 usernameField.width = 500;
 usernameField.height = 90;
 usernameField.defaultTextFormat = flst;
 addChild(usernameField);
 return usernameField;

 var passwordField:TLFTextField = new TLFTextField();
 passwordField.x = 208.05;
 passwordField.y = 369;
 passwordField.width = 500;
 passwordField.height = 90;
 passwordField.defaultTextFormat = flst;
 addChild(passwordField);
 return passwordField ;
1

1 Answers

1
votes

You simply didnt set the text =) And dont need to return something.

This works:

stop();

 import fl.text.TLFTextField;
 import flash.text.TextFormat;

 //formatLoginScreenText = flst
 var flst:TextFormat = new TextFormat();
 flst.font = "Verdana";
 flst.size = 20;
 flst.align = TextFieldAutoSize.CENTER;

 //The Actual TextFields
 var usernameField:TLFTextField = new TLFTextField();
 usernameField.x = 208.05;
 usernameField.y = 209;
 usernameField.width = 500;
 usernameField.height = 90;
 usernameField.text = "username";
 usernameField.defaultTextFormat = flst;
 addChild(usernameField);

 var passwordField:TLFTextField = new TLFTextField();
 passwordField.x = 208.05;
 passwordField.y = 369;
 passwordField.width = 500;
 passwordField.height = 90;
 passwordField.defaultTextFormat = flst;
 passwordField.text = "password";
 addChild(passwordField);

And if you want the text to be editable do this:

passwordField.selectable = true;
passwordField.type = TextFieldType.INPUT;