In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Text Sewer

Inspired by header made in Keith Peters old website (www.bit-101.com) header.

Using HitTester class made by Doug McCune.

Click to clear the screen
Get Adobe Flash player
by hidrodixtion2 26 Jun 2011
/**
 * Copyright hidrodixtion2 ( http://wonderfl.net/user/hidrodixtion2 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/n9vH
 */

package {
    import flash.events.MouseEvent;    
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.filters.DropShadowFilter;
    import flash.geom.Point;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    
    public class FlashTest extends Sprite {
        private var _lines:Sprite;        
        private var _bd:BitmapData;
        private var _bmp:Bitmap;
        private var _tf:TextField;
        private var _tfor:TextFormat;        
        
        public function FlashTest() {            
            _lines = new Sprite();            
            _bd = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x00000000);
            _bmp = new Bitmap(_bd);            
            _bmp.filters = [new DropShadowFilter()];
            
            addChild(_lines);
            addChild(_bmp);
            
            makeText();
        }
        
        private function makeText():void
        {
            _tfor = new TextFormat();
            _tfor.size = 190;
            _tfor.font = "Arial Black";            
            _tfor.color = 0xFFFFFF;
            
            _tf = new TextField();
            _tf.selectable = false;
            _tf.text = "WDRFL";            
            _tf.autoSize = TextFieldAutoSize.LEFT;
            _tf.setTextFormat(_tfor);
            _tf.y = 125;            
            
            addChildAt(_tf, 0);            
        
            addEventListener(MouseEvent.CLICK, clearScreen);    
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        private function clearScreen(e:MouseEvent):void {
            var _s:Sprite = new Sprite();
            _bd.fillRect(_bd.rect, 0);
            _bd.draw(_s);
            _s = null;
        }
        
        protected function onEnterFrame(e:Event):void
        {
            // 50 in loop determine how much line is drawn and tested at one time
            for (var i:uint = 0; i<50; i++) {
                sewText(50);
            }
        }
        
        private function sewText(dist:int):void {
            var distance:int = dist;
            var sewX:Number = Math.random() * stage.stageWidth;
            var sewY:Number = Math.random() * stage.stageHeight;
            var distX:Number = sewX + Math.random() * distance - (distance/2);
            var distY:Number = sewY + Math.random() * distance - (distance/2);
            
            if (HitTester.realHitTest(_tf, new Point(sewX, sewY)) && HitTester.realHitTest(_tf, new Point(distX, distY))) {
                _lines.graphics.lineStyle(0, 0, 0.2);
                _lines.graphics.moveTo(sewX, sewY);
                _lines.graphics.lineTo(distX, distY);
                _bd.draw(_lines);
                _lines.graphics.clear();
            }            
        }
    }
}
    
    // HitTester class, made by Doug McCune (http://dougmccune.com/blog/2007/02/03/using-hittestpoint-or-hittest-on-transparent-png-images/)
    // this class is originally used to check the HitTest with transparent PNG, but I found that this is very useful to use with TextField,
    // as we know that we can't make precision hit test on TextField because Text Field made a rectangle wrapping it's letter/text.
    
    import flash.display.BitmapData;
    import flash.display.DisplayObject;
    import flash.geom.Matrix;
    import flash.geom.Point;
    
    class HitTester
    {
        public static function realHitTest(object:DisplayObject, point:Point):Boolean {
            /* If we're already dealing with a BitmapData object then we just use the hitTest
             * method of that BitmapData.
             */
            if(object is BitmapData) {
                return (object as BitmapData).hitTest(new Point(0,0), 0, object.globalToLocal(point));
            }
            else {
                
                /* First we check if the hitTestPoint method returns false. If it does, that
                 * means that we definitely do not have a hit, so we return false. But if this
                 * returns true, we still don't know 100% that we have a hit because it might
                 * be a transparent part of the image. 
                 */
                if(!object.hitTestPoint(point.x, point.y, true)) {
                    return false;
                }
                else {
                    /* So now we make a new BitmapData object and draw the pixels of our object
                     * in there. Then we use the hitTest method of that BitmapData object to
                     * really find out of we have a hit or not.
                     */
                    var bmapData:BitmapData = new BitmapData(object.width, object.height, true, 0x00000000);
                    bmapData.draw(object, new Matrix());
                    
                    var returnVal:Boolean = bmapData.hitTest(new Point(0,0), 0, object.globalToLocal(point));
                    
                    bmapData.dispose();
                    
                    return returnVal;
                }
            }
        }
    }