【egret】 输入文本的使用

记下来,怕之后自己忘记~

创建输入文本

private text: egret.TextField;
private init (){
    this.text: egret.TextField = this.createShuRuText([100,100]);
}

private createShuRuText( point: any[] ): egret.TextField {
        var txInput: egret.TextField = new egret.TextField;
        txInput.type = egret.TextFieldType.INPUT;
        txInput.size = 35;
        txInput.width = 300;
        txInput.height = 43;
        txInput.anchorOffsetY = txInput.height;
        txInput.x = point[0];
        txInput.y = point[1];
        txInput.textColor = 0x000000;
//      this.layTxBg( txInput );
        this.addChild( txInput );
        return txInput;
    }

获取输入内容

private addEvent (){
    this.text.addEventListener( egret.Event.CHANGE, function (evt: egret.Event){
    console.log(evt.target.text);
}, this );
}

给输入文本添加背景的工具

private layTxBg( tx: egret.TextField ): void {
        var shp: egret.Shape = new egret.Shape;
        shp.graphics.beginFill( 0x000000 );
        shp.graphics.drawRect( tx.x, tx.y, tx.width, tx.height );
        shp.graphics.endFill();
        shp.anchorOffsetY = shp.height;
        this.addChild( shp );
    }
经验分享 程序员 微信小程序 职场和发展