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

flash on 2010-11-30

Get Adobe Flash player
by geko 04 Dec 2010
    Embed
/**
 * Copyright geko ( http://wonderfl.net/user/geko )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/sDOn
 */

package {
    import flash.display.Sprite;
    import flash.display.Shape;
    import flash.display.GraphicsPath;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import com.bit101.components.PushButton;
    
    public class FlashTest extends Sprite {
        public var ants:Shape;
        public var antsPath:GraphicsPath;
        public var commands:Vector.<int> = new Vector.<int>();
        public var data:Vector.<Number> = new Vector.<Number>();
        public var lineMatrix:Matrix = new Matrix();
        public var fillMatrix:Matrix = new Matrix();
        public var point:Point;
        public var bt:PushButton;
        
        public function FlashTest() {
            ants = addChild(new Shape) as Shape;
            antsPath = new GraphicsPath();
            //mtrx = new Matrix();
            //path = new GraphicsPath();
            bt = new PushButton(this, 0, 0, "clear", clear);
            
            lineMatrix.createGradientBox(5, 5, Math.PI/4, 0, 0);
            fillMatrix.createGradientBox(5, 5, Math.PI/4, 0, 0);
            
            stage.addEventListener(MouseEvent.MOUSE_DOWN, mouse);
            stage.addEventListener(MouseEvent.MOUSE_UP, mouse);
            stage.addEventListener(Event.ENTER_FRAME, marchingAnts);
        }
        
        public function mouse(event:MouseEvent):void{
            switch(event.type){
                case MouseEvent.MOUSE_DOWN:
                    //graphics.lineStyle(1, 0x124253);
                    //graphics.beginFill(0x273484);
                    
                    //ants.graphics.lineStyle(3, 0x0000FF, 0.5);
                    //ants.graphics.moveTo(mouseX, mouseY);
                    antsPath.moveTo(mouseX, mouseY);
                    point = new Point(mouseX, mouseY);
                    stage.addEventListener(MouseEvent.MOUSE_MOVE, mouse);
                break;
                case MouseEvent.MOUSE_UP:
                    stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouse);
                    //ants.graphics.clear();
                    antsPath.lineTo(point.x, point.y);
                    this.graphics.beginFill(1,0.4);
                    this.graphics.drawPath(antsPath.commands, antsPath.data);
                    this.graphics.endFill();
                    //for each(var _command:int in antsPath.commands) commands.push(_command);
                    //for each(var _data:Number in antsPath.data) data.push(_data);
                    //antsPath.commands = new Vector.<int>();
                    //antsPath.data = new Vector.<int>();
                    antsPath = new GraphicsPath();                   
                break;
                case MouseEvent.MOUSE_MOVE:
                    antsPath.lineTo(mouseX, mouseY);
                break;
            }
            event.updateAfterEvent();
        }
        
        public function marchingAnts(event:Event):void{
            ants.graphics.clear();
            ants.graphics.lineStyle(1);
            ants.graphics.lineGradientStyle("linear", [0x000000, 0xFFFFFF], [1, 1], [0xFF/2, 0xFF/2+1], lineMatrix, "repeat");
            ants.graphics.drawPath(antsPath.commands, antsPath.data);
            /*
            this.graphics.clear();
            //this.graphics.lineStyle(1);
            this.graphics.beginGradientFill("linear", [0x000000, 0xFFFFFF], [1, 1], [0xFF/2, 0xFF/2+1], fillMatrix, "repeat");         
            this.graphics.drawPath(commands, data);
            this.graphics.endFill();
            */
            lineMatrix.tx += 0.1;
            //fillMatrix.tx -= 2;
        }
        
        public function clear():void{
            graphics.clear();
            //while(commands) commands.shift();
            //while(data) data.shift();
        }
    }
}