package ch12_1
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.*;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.geom.Rectangle;
import flash.filters.GlowFilter;
import flash.filters.DropShadowFilter;
public class ColorTextField extends Sprite
{
private var tf:TextField = new TextField();
private var f:TextFormat = new TextFormat();
private var worlds:String ="\n dear:\n 爱情从来都是一种束缚,追求爱情并不等于追求自由。自由可贵,我们用这最宝贵的东西换取爱情。因为爱一个人,明知会失去自由,也甘愿作出承诺。诺言是用来跟一切的变幻抗衡。变幻原是永恒,我们唯有用永恒的诺言制约世事的变幻。不能永恒的,便不是诺言。诺言是很贵的,如果你尊重自己的人格。";
private var bmd:BitmapData ;
private var bm:Bitmap ;
private var count:int=0;
public function ColorTextField()
{
f.size =20;
f.leading =20;
tf.border =true;
tf.wordWrap =true;
tf.multiline =true;
tf.defaultTextFormat =f;
tf.width = 400;
tf.height =500;
bmd = new BitmapData(tf.width+1,tf.height+1,true,0xFFFFFF);
bmd.draw(tf);
bm = new Bitmap(bmd);
bm.x =(stage.stageWidth-bm.width)/2;
bm.y =(stage.stageHeight-bm.height)/2;
stage.addChild(bm);
stage.addEventListener(Event.EXIT_FRAME,changle);
}
private function changle(e:Event):void
{
if(count<worlds.length)
{
var insert:String =worlds.substr(count,1);
count++;
tf.appendText(insert);
reDraw();
}
}
private function reDraw():void
{
var rec:Rectangle = tf.getCharBoundaries(tf.length-1);
bmd.draw(tf,null,null,null,rec);
bmd.applyFilter(bmd,rec,rec.topLeft,new GlowFilter(0xFFFFFF*Math.random(),1,2,2,10));
bmd.applyFilter(bmd,rec,rec.topLeft,new DropShadowFilter(0.5,0.5));
}
}
}
AS3.0实现彩色文字效果
最新推荐文章于 2022-08-21 10:19:25 发布