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

Wonderfl Banner

Get Adobe Flash player
by yd_niku 16 Apr 2009
package {
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.filters.*;
    import flash.geom.*;
    import flash.system.*;
    import flash.text.*;
    import com.flashdynamix.utils.SWFProfiler;
    public class Banner extends Sprite {
        public static const PROXY:String = "http://5ivestar.org/proxy/";
        public static const CROSSDOMAIN:String = "http://5ivestar.org/proxy/crossdomain.xml";
        private var _statuField:TextField;
        public function Banner() {
            Security.loadPolicyFile( CROSSDOMAIN );
            addEventListener( Event.ADDED_TO_STAGE, onAdded );
        }
        private function onAdded( e:Event = null ) :void {
            removeEventListener( Event.ADDED_TO_STAGE, onAdded );
			
	    SWFProfiler.init( this );

            _statuField = new TextField();
            addChild( _statuField );
            
            _statuField.text = "Loading...";
            var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener( Event.COMPLETE, onLoadImage );
            loader.load( new URLRequest( PROXY+"http://level0.kayac.com/shared/images/bnr_wonderfl.gif"), new LoaderContext( true ) );
        }
        private function onLoadImage( e:Event ) :void {
            _statuField.text = "";

            LoaderInfo(e.currentTarget).removeEventListener( Event.COMPLETE, onLoadImage );
            var img :Bitmap = Loader(e.currentTarget.loader).content as Bitmap;
           
            var bmp:BitmapData = img.bitmapData;

            const W:Number = stage.stageWidth;
            const H:Number = stage.stageHeight;
            RECT = new Rectangle( 0, 0, W, H );

            var c:uint;
            const WHITE :uint = 0xFFFFFF;

            var offset:Point = new Point( Math.round(( W-bmp.width)* 0.5),Math.round( (H-bmp.height)* 0.5) );
            for( var i:int=0; i<bmp.width; ++i  ) {
                for ( var j:int = 0; j < bmp.height; ++j  ) {
                    //c = bmp.getPixel( i, j );
                    if ( ( c = bmp.getPixel( i, j ) )  == WHITE ) continue;
                    var px:PixelData  = new PixelData( i+offset.x,j+offset.y, c );
                    px.setDefault( Math.random() * W, Math.random() * H );
                    px.next = _pixel;
                    _pixel = px;
                }
            }

            bmp.dispose(); bmp = null; img = null;

            var rect :Sprite = new Rect( 0x0, 0, W, H );
            rect.buttonMode = true; 
            rect.addEventListener( MouseEvent.ROLL_OVER, onRollOverHandler );
            rect.addEventListener( MouseEvent.CLICK, onClickHandler );
            addChild( rect );

            _canvas = new BitmapData( W, H, false, 0xFFFFFF );
            addChild( new Bitmap( _canvas ) );
            addEventListener( Event.ENTER_FRAME, onRender );
        }

        private var _pixel :PixelData;
        private var _canvas :BitmapData;
        private var RECT:Rectangle;
        private const SPRING:Number = 0.032;
        private const FRICTION:Number = 0.89;
        private function onRender (e:Event) :void {
            var px:PixelData = _pixel;
            while ( ( px = px.next  ) != null ) {
                px.x = ( px.vx = ( ( px.sx - px.x ) * SPRING + px.vx ) * FRICTION ) + px.x;
                px.y = ( px.vy = ( ( px.sy - px.y ) * SPRING + px.vy ) * FRICTION ) + px.y;
            }
            var round:Function = Math.round;
            px = _pixel;
            var canvas:BitmapData = _canvas;
            canvas.fillRect( RECT, 0xFFFFFF );
            canvas.lock();
            while ( ( px = px.next  ) != null ) {
                canvas.setPixel( round(px.x), round(px.y), px.c );
            }
            canvas.unlock();
        }
        private function onClickHandler( e:MouseEvent ):void {
            navigateToURL( new URLRequest("http://wonderfl.kayac.com/"), "_blank" );
        }
        private function onRollOverHandler ( e:MouseEvent ):void {
            var px:PixelData = _pixel;
            while( ( px = px.next  ) != null ) {
                px.revert();
            }
        }
    }
}
import flash.display.*;
class Rect extends Sprite {
    public function Rect ( c:uint = 0xFF0000, a:Number= 1.0, width:Number= 100, height:Number=100 ){
        graphics.beginFill( c, a );
        graphics.drawRect( 0, 0, width, height );
        graphics.endFill();
    }
}

class PixelData {
    public var sx:Number = 0;
    public var sy:Number = 0;
    public var x:Number = 0;
    public var y:Number = 0;
    public var vx:Number = 0;
    public var vy:Number = 0;
    public var c:uint= 0;
    public var next:PixelData;
	
    public var cx:Number = 0;
    public var cy:Number = 0;
    public function PixelData ( sx:Number, sy:Number, sc :uint ) {
        this.sx = sx;
        this.sy = sy;
        c = sc;
    }
    public function setDefault( tx:int, ty:int ):void {
        cx = x = tx;
        cy = y = ty;
    }
    public function revert():void {
        x = cx;
        y = cy;
    }
}