Rasterizing, then dissolving a TextField : Effects « TextField « Flash / Flex / ActionScript






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

1.Applying Advanced Anti-Aliasing
2.Make whole TextField italic
3.Set Text box grid fit type to pixel
4.ClickableText
5.the text appears fully opaque, even though the text field's alpha percentage is set to 20%:
6.a list of bulleted text