TextFields are created in AS3 basically like most other objects, by first defining and then instantiating them:
Here the code of a function I use for creating my textfields. still basic, but displays the most common settings needed for your dynamic textField. assumingyou have a font added in the library with the class instance name "_tahoma": One issue I discovered that I can't really explain, is that I often have to reassign the textFormat to the TextField when changing the fields content: http://livedocs.adobe.com/flex/201/langref/flash/display/Stage.html#focus in AS3, it's now a property rather than a function that you call. Also, you don't use the text name value of the field, but a reference to the actual field itself... would look something like:
setting the focus on an input field:
Recent News
Posted by sortofme on February 26th, 2008
Actionscript:
</code>
package {
import flash.display.Sprite;
import flash.text.*;
public class whynot extends Sprite{
private var display_txt:TextField;
public function whynot(){
display_txt = new TextField();
display_txt.text = "a text";
addChild(display_txt);
}
}
}
Actionscript:
private function makeTextField():void {
var tahoma:Font = new _tahoma();
TFFormat = new TextFormat();
TFFormat.font =tahoma.fontName;
TFFormat.color = "0xFFFFFF";
TFFormat.size = 11;
TextField = new TextField();
TextField.width = 200;
TextField.height = height;
TextField.x = 42;
TextField.y = 10;
TextField.wordWrap = true;
TextField.selectable = false;
TextField.border = true;
TextField.multiline = false;
TextField.embedFonts = true;
TextField.autoSize = TextFieldAutoSize.LEFT;
TextField.antiAliasType = AntiAliasType.ADVANCED;
addChild(alertTextField);
alertTextField.setTextFormat(alertTFFormat);
};
Actionscript:
alertTextField.text = myString;
alertTextField.setTextFormat(alertTFFormat);
Actionscript:
myObj.stage.focus = myTextField;
Recent Comments