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

なんちゃって破線

Get Adobe Flash player
by keno42 27 Feb 2009

    Tags

    Embed
package {
    import flash.display.GradientType;
    import flash.display.SpreadMethod;
    import flash.display.Sprite;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import flash.events.MouseEvent;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..
            stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
            onMouseMove();
        }
        private function onMouseMove(event:MouseEvent = null):void{
            var scale:Number = 0.125 + stage.mouseX / 400;
            this.graphics.clear();
            this.graphics.lineStyle(10);
            drawDashedLine( this, new Point(10,10), new Point(400,10), [1,0], 90 * scale );
            drawDashedLine( this, new Point(400,10), new Point(400,400), [1,1,0], 90 * scale );
            drawDashedLine( this, new Point(400,400), new Point(10,400), [1,1,1,0], 90 * scale );
            drawDashedLine( this, new Point(10,400), new Point(10,10), [1,1,1,0,1,0], 90 * scale );
            this.graphics.lineStyle(5);
            drawDashedLine( this, new Point(50,50), new Point(250,50), [1,0,1], 100 * scale );
            drawDashedLine( this, new Point(50,80), new Point(250,80), [1,0,1], 50 * scale );
            drawDashedLine( this, new Point(50,110), new Point(250,110), [1,0,1], 18 * scale );
            drawDashedLine( this, new Point(50,140), new Point(250,240), [1,0,1], 12 * scale );
            drawDashedLine( this, new Point(50,170), new Point(250,370), [1,0,1], 6 * scale );
            this.graphics.lineStyle(6);
            drawDashedLine( this, new Point(350,50), new Point(350,350), [1,0,0,0,1,0], 60 * scale );
            this.graphics.lineStyle(4);
            drawDashedLine( this, new Point(320,50), new Point(320,350), [1,0,0,0,1,0], 60 * scale );
            this.graphics.lineStyle(2);
            drawDashedLine( this, new Point(290,50), new Point(290,350), [1,0,0,0,1,0], 60 * scale );
        }
        private function drawDashedLine( sprite:Sprite, drawFrom:Point, drawTo:Point, pattern:Array, length:Number, color:uint = 0x000000):void{
            var unit:Number = 255 / pattern.length;
            var lastBit:Boolean = pattern[0];
            var lastLength:Number = 0;
            var colorArray:Array = [color, color];
            var alphaArray:Array = lastBit?[1,1]:[0,0];
            var ratioArray:Array = [0];
            var magicNum:Number = length / 750.0;
            var tempPoint:Point = drawTo.subtract(drawFrom);
            tempPoint.normalize(magicNum);
            var matrix:Matrix = new Matrix(
                tempPoint.x,tempPoint.y,
                -tempPoint.y,tempPoint.x,
                drawFrom.x,drawFrom.y
            );
            for( var i:int = 0; i<pattern.length; i++ ){
                if( lastBit != pattern[i] ){
                    colorArray.push( color, color );
                    lastBit?
                        alphaArray.push( 0,0 ):
                        alphaArray.push( 1,1 );
                    ratioArray.push( Math.round(lastLength), Math.round(lastLength) );
                    lastBit = !lastBit;
                }
                lastLength+=unit;
            }
            ratioArray.push( 255 );
            sprite.graphics.lineGradientStyle(
                GradientType.LINEAR,
                colorArray,
                alphaArray,
                ratioArray,
                matrix,
                SpreadMethod.REPEAT
            );
            sprite.graphics.moveTo(drawFrom.x, drawFrom.y);
            sprite.graphics.lineTo(drawTo.x, drawTo.y);
        return;
    }
}
}