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

forked from: forked from: flash on 2009-3-14

Get Adobe Flash player
by s8t1h12akj 01 Apr 2013
    Embed
// forked from bradsedito's forked from: flash on 2009-3-14
// forked from hiro_rec's flash on 2009-3-14
package
{
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.text.*;
    import flash.utils.Timer;
    
    
    [SWF(width="456", height="456", backgroundColor="0xFFFFFF", frameRate="30")]
    
    public class Main extends Sprite {
        
        private const W:int = stage.stageWidth;
        private const H:int = stage.stageHeight;
        private const MAX_REP:int = 50;
        
        private var container:Sprite = new Sprite();
        private var bmd:BitmapData;
        private var bmp:Bitmap = new Bitmap();
        
        private var txtFld:TextField = new TextField();
        private var txtContainer:Sprite = new Sprite();
        private var txtBmd:BitmapData;
        private var txtBmp:Bitmap = new Bitmap();
        
        private var previewContainer:Sprite = new Sprite();
        
        private var dropShadow:DropShadowFilter = new DropShadowFilter(4.0, 45, 0x000000, 1, 4.0, 4.0, 10, 1);
        private var glowFilter:GlowFilter = new GlowFilter(0x003366, 1, 1, 1, 5, 1);
        private var glowFilter2:GlowFilter = new GlowFilter(0xFFFFFF, 1, 4, 4, 10, 1);
        
        private var txt1:String = "Akijii HP.";
        private var txt2:String = "BradSedito.\n";
        private var txt3:String = "...BradSedito.";
        private var txt4:String = "BradSedito!"; 
        
        private var txtList1:Array = txt1.split("");
        private var txtList2:Array = txt2.split("");
        private var txtList3:Array = txt3.split("");
        private var txtList4:Array = txt4.split("");
        
        private var txtGroup:Array = [txtList1, txtList2, txtList3, txtList4];
        private var txtGroupCount:int = 0;
        
        private var timer:Timer = new Timer(300);
        
        private var textColor:uint = Math.random() * 0xFFFFFF;
        
        
        public function Main()
        {
            
            timer.addEventListener(TimerEvent.TIMER, timerHandler);
            addEventListener(Event.ENTER_FRAME, enterFrameHandler);
            stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
            
            timer.start();
            
            resetBitmap();
            previewContainer.addChild(bmp);
            previewContainer.filters = [glowFilter2, glowFilter, dropShadow];
            
            addChild(previewContainer);
            
            setText()
            addText();
        }
        
        private function resetBitmap():void
        {
            if(bmd) bmd.dispose();
            bmd = new BitmapData(W, H, true, 0x00000000);
            bmp.bitmapData = bmd;
        }
        
        private function mouseDownHandler(event:MouseEvent):void
        {
            textColor = Math.random() * 0xFFFFFF;
            
            resetBitmap();
            resetText();
            timer.reset();
            txtGroupCount++;
            if(txtGroupCount == txtGroup.length){
                txtGroupCount = 0;
            }
            setText()
            addText();
            timer.start();
        }
        
        private function resetText():void
        {
            txtFld.text = "";
            captText();
        }
        
        private function timerHandler(event:TimerEvent):void
        {
            addText()
            
            if(timer.currentCount == txtGroup[txtGroupCount].length-1){
                timer.reset();
            }
        }
        
        private function addText():void
        {
            txtFld.appendText(txtGroup[txtGroupCount][timer.currentCount]);
            captText();
        }
        
        private function setText():void
        {
            txtFld.multiline = true;

            var format:TextFormat = new TextFormat();
            format.size = 40;
            format.font = "Osaka"
            format.letterSpacing = 2;
            txtFld.defaultTextFormat = format;
            
            txtFld.autoSize = TextFieldAutoSize.LEFT;
        }
        
        private function captText():void
        {
            if(txtBmd) txtBmd.dispose();
            txtBmd = new BitmapData(txtFld.width, txtFld.height, true, 0x00000000);
            txtContainer.addChild(txtFld);
            txtBmd.draw(txtContainer);
            txtContainer.removeChild(txtFld);
            txtBmp.bitmapData = txtBmd;
        }
        
        
        private function enterFrameHandler(event:Event):void
        {
            render();
        }
        
        private function render():void
        {
            for(var i:int=0; i<MAX_REP; i++)
            {
                var circle:Sprite = createCircle();
                var px:int = Math.random()*(txtBmp.x + txtBmp.width);
                var py:int = Math.random()*(txtBmp.y + txtBmp.height);
                var col:uint = txtBmd.getPixel32(px, py);
                
                
                if(col > 0){
                    circle.x = px;
                    circle.y = py;
                    container.addChild(circle);
                    bmd.draw(container);
                    container.removeChild(circle);
                }
            }
            
            var dx:Number = W/2 - txtBmp.width/2;
            var dy:Number = H/2 - txtBmp.height/2;
            previewContainer.x += (dx - previewContainer.x) * 0.2;
            previewContainer.y += (dy - previewContainer.y) * 0.2;
        }
        
        private function createCircle():Sprite
        {
            var circle:Sprite = new Sprite();
            circle.graphics.beginFill(textColor);
            circle.graphics.drawCircle(0, 0, Math.random()*2+1);
            circle.graphics.drawRect(0, 0, Math.random()*2, Math.random()*2);
            circle.graphics.endFill();
            
            return circle;
        }
        
    }
}