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


Flash / Flex / ActionScript examples » TextField » Effects »

 

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(00);
    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 == && coloredRegion.height == ) {
        t.stop(  );
      }
    }
  }
}

        



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


Flash / Flex / ActionScript examples

 Navioo TextField
» Effects