Create a textfield

We can display a text in flash. Use TextField class.

We also can create form input.

It's possible to use HTML format in a textfield.

By default the type of a TextField is STATIC (can't be changed dynamiclly). You also can useDYNAMIC type or INPUT type.

In the example below we're going to create three differents Textfields in order to understand the differences.The first one is a simple static textfield, where text can't be selectionable. The second is a textfield with an INPUT type. The text value in this one will be writable. And finnally the third textfield displays HTML text.

 
package;
import flash.Lib;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFieldAutoSize;

      class Main
      {
      		static function main()
      		{
      			new Main();
      		}
      		public function new()
      		{
      			var monText = new TextField();
      			monText.text = "Simple champs texte statique.";
      			monText.autoSize = TextFieldAutoSize.CENTER;
      			monText.selectable = false;
      			monText.x = 0;   					
      			Lib.current.addChild(monText);

      			var monText2 = new TextField();
      			monText2.text = "Champs de text de type INPUT";
			monText2.autoSize = TextFieldAutoSize.CENTER;
			monText2.type = TextFieldType.INPUT;
			monText2.border = true;
			monText2.borderColor = 0x999999;
			monText2.background = true;
			monText2.backgroundColor = 0xCCCCCC;
			monText2.x = monText.x;
			monText2.y = monText.y + monText.height;

      			Lib.current.addChild(monText2);

      			var monText3 = new TextField();
      			monText3.htmlText = "<b> Text HTML</b>";
      			monText3.autoSize = TextFieldAutoSize.CENTER;
      			monText3.x = monText2.x;
			monText3.y = monText2.y + monText2.height;
			
      			Lib.current.addChild(monText3);      			
      		}
      }

Compile and t(e)ast(e) it!

haxe -swf9 ../bin/output.swf -main Main 

output

Alternative content

Get Adobe Flash player

(30 times)