文本的处理其实可以很丰富,下面是渐变文字显示的一种处理方式。
private var _gradientBox:Shape;
private var _colors:Array = [0xfffac7,0xd6b327,0x9d6c25 ];
private var _alphas:Array = [1,1,1];
private var _ratios:Array = [0x00,187, 0xFF];
private var _currentMatrix:Matrix;
[Embed(source="MSYH.TTF", fontName="myMSYHFont",mimeType="application/x-font" ,embedAsCFF="false")]
public var myMSYHFontClass:Class;//微软雅黑
public function test():void
{
Font.registerFont(myMSYHFontClass);//注册字体
var _txt:TextField = new TextField();
_txt.x = 20;
_txt.y = 50;
_txt.width = 200;
var tlf:TextFormat = new TextFormat();
tlf.font = "微软雅黑";
tlf.size = 14;
tlf.bold = true;
_txt.defaultTextFormat = tlf;
_txt.embedFonts = true;
_txt.text = "神阿斯顿阿斯顿爱上";
this._currentMatrix = new Matrix();
this._currentMatrix.createGradientBox(_txt.textWidth, _txt.textHeight, Math.PI / 2, 0, 0);
if (this._gradientBox == null)
{
this._gradientBox = new Shape();
}
this._gradientBox.graphics.clear();
this._gradientBox.graphics.beginGradientFill(GradientType.LINEAR,_colors, this._alphas, this._ratios, this._currentMatrix);
this._gradientBox.graphics.drawRect(0, 0, _txt.textWidth, _txt.textHeight);
this._gradientBox.graphics.endFill();
if (_txt)
{
addChild(_txt);
_txt.cacheAsBitmap = true;
}
if (this._gradientBox)
{
this._gradientBox.x = _txt.x;
this._gradientBox.y = _txt.y;
addChild(this._gradientBox);
this._gradientBox.cacheAsBitmap = true;
this._gradientBox.mask = _txt;
}
this.filters = [new GlowFilter(0x000000,1,2,2,10)];
}