我一直在寻找一种方法,在过去几个小时内在TextField组件上放置渐变色,没有运气。一种方法是创建一个渐变矩形并将TextField设置为它的掩码,但我无法使其工作:
var m:MovieClip = new MovieClip();
var mTxt:Sprite = new Sprite();
var txt:TextField = new TextField();
var tf:TextFormat = new TextFormat();
var dropShadow:DropShadowFilter = new DropShadowFilter();
dropShadow.distance = 0;
dropShadow.angle = 120;
dropShadow.color = 0x000000;
dropShadow.alpha = 1;
dropShadow.blurX = 2;
dropShadow.blurY = 2;
dropShadow.strength = 1;
dropShadow.quality = 80;
dropShadow.inner = false;
dropShadow.knockout = false;
dropShadow.hideObject = false;
txt.filters = new Array(dropShadow);
tf.font = "Ethnocentric Rg";
tf.color = 0xffde00;
tf.size = 72;
txt.defaultTextFormat = tf;
txt.text = "1756.25";
mTxt.addChild(txt);
var fillType:String = GradientType.LINEAR;
var colors:Array = [0xFF0000, 0x0000FF];
var alphas:Array = [1, 1];
var ratios:Array = [0x00, 0xFF];
var matr:Matrix = new Matrix();
matr.createGradientBox(400, 100, 0, 0, 0);
var spreadMethod:String = SpreadMethod.REFLECT;
m.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);
m.graphics.drawRect(0,0,400,120);
m.mask = mTxt;
addChild( m );
此代码确实崩溃了AIR调试程序并退出了自身。 我在这里做错了什么?
答案 0 :(得分:1)
将cacheAsBitmap设置为true,并确保将掩码添加到舞台。
m.cacheAsBitmap = mTxt.cacheAsBitmap = true;
m.mask = mTxt;
addChild( m );
addChild( mTxt );
答案 1 :(得分:0)
我必须将两个图层的cacheAsBitmap选项设置为true:
txt.cacheAsBitmap = true;
m.cacheAsBitmap = true;
addChild( m );
addChild(txt);
m.mask = txt;