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: Simple Shape Generator

// forked from paespedro's Simple Shape Generator
package {
    
    
    import flash.filters.DropShadowFilter;
    import flash.display.DisplayObject;
    import flash.display.Graphics;
    import flash.display.Sprite;
    import flash.display.Shape
    import flash.display.MovieClip
    import flash.events.Event
    import flash.events.MouseEvent
    import flash.text.TextField
    import flash.geom.ColorTransform;
    import flash.filters.BlurFilter;
    import flash.filters.BitmapFilter
    import flash.display.BitmapData
    import flash.display.Bitmap

    public class ShapeExample extends MovieClip{
        private var onStage:Boolean = false;
        private var shapeType:String = "Rect";
        private var statText:TextField = new TextField();
        public var itemsAmount:uint = 300;
        private var _items:Vector.<MovieClip> = new Vector.<MovieClip>();
        public function ShapeExample():void{
            stage.frameRate = 30;

            stage.addEventListener(Event.ADDED_TO_STAGE, startIt);
            stage.addEventListener(Event.MOUSE_LEAVE, stopIt);
            stage.addEventListener(MouseEvent.MOUSE_MOVE, startIt);
            stage.addEventListener(MouseEvent.MOUSE_DOWN, changeShapeType);
            statText.autoSize = "left";
            statText.text = "Just put your mouse on the screen";
            addChild(statText);   
            for(var i:uint = 0; i < itemsAmount; ++i){
                var item:Sprite = getShape('Rect');
                addChild(item);
                _items.push(item);
            }
            
            var bg:Shape = new Shape;
            bg.graphics.beginFill(0xff0000);
            bg.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
            bg.graphics.endFill();
            stage.addChildAt(bg, 0);
        }
        /*
        * 
        */
        private function getShape(shapeType:String = 'Circle'):MovieClip
        {
            var item:MovieClip = new MovieClip();
            item.color = {r:0,g:0,b:0};
            item.type = shapeType;
            item.radians = Math.PI;
            item.graphics.beginFill(0x000000);
            if(shapeType == "Circle"){
                item.graphics.drawCircle(50, 50, 50);
            }else{
                item.graphics.drawRoundRect(-40, -100, 80, 200, 100);
            }
            item.graphics.endFill();   
            item.x = item.px = -100+(Math.random()*(stage.stageWidth+200));
            item.y = stage.stageHeight+100;
            item.transform.colorTransform = new ColorTransform(1, 1, 1, 1, -255, -255, -255);
            item.scaleX = item.scaleY = .5+Math.random()*.5;
            return(item);
        }
        /*
        * 
        */        
        private function changeShapeType(event:Event):void{
            shapeType = shapeType == "Rect" ? "Circle" : "Rect";
        }
        /*
        * 
        */
        private function startIt(event:Event):void{
            onStage = true;
            addEventListener(Event.ENTER_FRAME, render, false, 0, true);
        }
        /*
        * 
        */
        private function stopIt(event:Event):void{
            statText.text = "LEFT STAGE";
            onStage = false;
            removeEventListener(Event.ENTER_FRAME, render);
        }
        /*
        * 
        */
        private function render(event:Event):void{
            statText.text = String(onStage ? "On Stage // ":"Out of Stage // ");
            for(var i:uint = 0; i < itemsAmount; ++i){
                var itemColor:ColorTransform = new ColorTransform();
                _items[i].y -= 2+(5*(i/itemsAmount));
                _items[i].color.r += 5;
                if(_items[i].color.r  >= 255){
                  _items[i].color.g  += 5;
                  if(_items[i].color.g >= 255){
                       _items[i].color.b += 5;
                   }
                }
                itemColor.color = uint("0x"+RGBtoHex(_items[i].color.r,_items[i].color.g,_items[i].color.b));
                _items[i].transform.colorTransform = itemColor;
                _items[i].radians += 0.05;
                _items[i].x = _items[i].px+(Math.sin(_items[i].radians)*100);
                if(_items[i].type == 'Rect'){
                    _items[i].rotation = Math.atan2(stage.mouseY-_items[i].y, (_items[i].x-_items[i].px))*(180/(Math.PI));
                }
                
                if(_items[i].y < -200){
                    _items[i].y = stage.stageHeight+100;
                    _items[i].color = {r:0,g:0,b:0};
                    _items[i].transform.colorTransform = new ColorTransform(1, 1, 1, 1, -255, -255, -255);
                    this.setChildIndex(_items[i], this.numChildren-1);
                }
            }
        }
        public function RGBtoHex(R:uint,G:uint,B:uint):* { // Copyright © 1999-2008, JavaScripter.net. 
            return toHex(R)+toHex(G)+toHex(B)
        }
        public function toHex(N:uint):* { // Copyright © 1999-2008, JavaScripter.net. 
             if (N==0) return "00";
             N=parseInt(String(N)); if (N==0 || isNaN(N)) return "00";
             N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
             return "0123456789ABCDEF".charAt((N-N%16)/16)
                  + "0123456789ABCDEF".charAt(N%16);
        }   
    }
}