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

Simple Shape Generator

package {
    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 mcID:uint = 0
        private var onStage:Boolean = false
        private var shapeType:String = "Rect"
        private var statText:TextField = new TextField()
        public function ShapeExample():void{
            stage.frameRate = 60
            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)
           //MovieClip(this.root).cacheAsBitmap = true
            statText.autoSize = "left"
            statText.text = "Just put your mouse on the screen"
            addChild(statText)           
        }
        
        private function changeShapeType(event:Event):void{
            shapeType = shapeType == "Rect" ? "Circle" : "Rect"
        }
        private function startIt(event:Event):void{
            onStage = true
            addEventListener(Event.ENTER_FRAME, drawIt)
        }
        private function stopIt(event:Event):void{
            statText.text = "LEAVED STAGE"
            onStage = false
            removeEventListener(Event.ENTER_FRAME, drawIt)
        }
        private function drawIt(event:Event):void{
            var artShape:Shape = new Shape()
            var artMc:MovieClip = new MovieClip()
            artMc.ID = mcID
            artMc.name = "art_"+mcID
            mcID++
            artShape.graphics.beginFill(0x000000);
            if(shapeType == "Circle"){
                artShape.graphics.drawCircle(50, 50, 50);
            }else{
                artShape.graphics.drawRoundRect(0, 0, 100, 100, 30);
            }
            artShape.graphics.endFill();            
            artMc.addChild(artShape)
            addChild(artMc)
            artMc.x = Math.random()*stage.stageWidth
            artMc.y = stage.stageHeight+50//mouseY-50
            manageElements(artMc)
            statText.text = String(onStage ? "On Stage // ":"Out of Stage // ")
        }
        private function manageElements(mc:MovieClip):void{
            mc.addEventListener(Event.ENTER_FRAME, killCircle)
            var shapeColor:ColorTransform = new ColorTransform()
            var r:Number= 0
            var g:Number= 0
            var b:Number= 0
            var pX:int = mc.x
            var pY:int = mc.y

            function killCircle(event:Event):void{
               event.currentTarget.y = pY-=3
               r += 5
               if(r >= 255){
                  g += 5
                  if(g >= 255){
                       b += 5
                   }
                }
             
                shapeColor.color = uint("0x"+RGBtoHex(r,g,b));
                event.currentTarget.transform.colorTransform = shapeColor
                event.currentTarget.scaleX -= .006
                event.currentTarget.scaleY -= .006
                if(shapeType == "Rect")event.currentTarget.rotation += 1
                if (event.currentTarget.scaleX <= 0){
                    statText.text = String((onStage ? "On Stage // ":"Out of Stage // ")+"Removing instance "+getChildByName(event.currentTarget.name).name)
                    event.currentTarget.removeEventListener(Event.ENTER_FRAME, killCircle)
                    removeChild(getChildByName(event.currentTarget.name))
                    
                }
            }
            function RGBtoHex(R:uint,G:uint,B:uint):* { // Copyright © 1999-2008, JavaScripter.net. 
                return toHex(R)+toHex(G)+toHex(B)
            }
            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);
            }                
        } 





    }
}