1, 普通文本
class Main extends egret.DisplayObjectContainer { public constructor() { super(); this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this); } /** * 文本类型, egret.TextField, 具体属性方法与事件, 请前往 * http://developer.egret.com/cn/apidoc/index/name/egret.TextField */ private onAddToStage(event: egret.Event) { var label:egret.TextField = new egret.TextField(); label.text = "This is a text!"; this.addChild( label ); } }
2, 输入文本
class Main extends egret.DisplayObjectContainer { public constructor() { super(); this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this); } /** * 1, 输入文本必须放到加入到显示列表得显示容器中 * 2, txInput.inputType 分为三种 => * -- 普通文本 egret.TextFieldInputType.TEXT * -- 密码文本 egret.TextFieldInputType.PASSWORD * -- 电话号码 egret.TextFieldInputType.TEL * 推荐: 输入文本最好放到某个 Sprite 显示类的实例中, 这样可以控制文本的背景宽高等 */ private onAddToStage(event: egret.Event) { var shp:egret.Sprite = new egret.Sprite(); shp.width = 640; shp.height = 50; shp.graphics.beginFill(0xffffff) shp.graphics.drawRect(0, 0, 640, 50); shp.graphics.endFill(); this.addChild(shp); var txInput:egret.TextField = new egret.TextField; txInput.type = egret.TextFieldType.INPUT; txInput.inputType = egret.TextFieldInputType.TEL; txInput.width = 640; txInput.height = 50; txInput.textColor = 0x000000; txInput.verticalAlign = egret.VerticalAlign.MIDDLE; txInput.size = 36; shp.addChild(txInput) } }