Text masking for stackoverlow

by www0z0k
click to change text
♥0 | Line 39 | Modified 2016-06-30 18:24:34 | MIT License
play

ActionScript3 source code

/**
 * Copyright www0z0k ( http://wonderfl.net/user/www0z0k )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/afdr
 */

package {
    import flash.text.TextFormat;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.display.BlendMode;
    import flash.events.MouseEvent;
    public class FlashTest extends Sprite {
        private var tf:TextField = new TextField();
        private var container:Sprite = new Sprite();
        private var toMask:Sprite = new Sprite();
        private const WIDTH:int = 250;
        private const HEIGHT:int = 150;
        public function FlashTest() {
            graphics.beginFill(0x0000ff);
            graphics.drawRect(0, 0, 300, 300);
            graphics.endFill();       
            
            addChild(container);     
            tf.defaultTextFormat = new TextFormat(null, 15, 0, true);
            tf.text = 'sample text ' + String(0 / 0);
            tf.cacheAsBitmap = true;
            container.blendMode = BlendMode.LAYER;
            toMask.blendMode = BlendMode.NORMAL;
            tf.blendMode = BlendMode.ALPHA;
            container.addChild(toMask);
            container.addChild(tf);
            toMask.graphics.beginFill(0x00ff00);
            toMask.graphics.drawRect(0, 0, WIDTH, HEIGHT);
            toMask.graphics.endFill();
            tf.width = WIDTH;
            tf.height = HEIGHT;
            stage.addEventListener(MouseEvent.CLICK, onClick);
        }
        
        private function onClick(e:MouseEvent = null):void{
            tf.text = 'sample text ' + Math.random();
        }
    }
}