Rasterizing, then dissolving a TextField
package {
import flash.display.*;
import flash.utils.*;
import flash.events.*;
import flash.geom.*;
import flash.text.*;
public class DissolveText extends Sprite {
private var randomSeed:int = Math.floor(Math.random( ) * int.MAX_VALUE);
private var destPoint:Point = new Point(0, 0);
private var numberOfPixels:int = 10;
private var destColor:uint = 0xFF000000;
private var bitmapData:BitmapData;
private var t:Timer;
public function DissolveText ( ) {
var txt:TextField = new TextField( );
txt.text = "Essential ActionScript 3.0";
txt.autoSize = TextFieldAutoSize.LEFT;
txt.textColor = 0xFFFFFF;
bitmapData = new BitmapData(txt.width, txt.height, false, destColor);
bitmapData.draw(txt);
var bitmap:Bitmap = new Bitmap(bitmapData);
addChild(bitmap);
t = new Timer(10);
t.addEventListener(TimerEvent.TIMER, timerListener);
t.start( );
}
private function timerListener (e:TimerEvent):void {
dissolve( );
}
public function dissolve( ):void {
randomSeed = bitmapData.pixelDissolve(bitmapData,
bitmapData.rect,
destPoint,
randomSeed,
numberOfPixels,
destColor);
var coloredRegion:Rectangle =
bitmapData.getColorBoundsRect(0xFFFFFFFF, destColor, false);
if (coloredRegion.width == 0 && coloredRegion.height == 0 ) {
t.stop( );
}
}
}
}
Related examples in the same category