Dead Code Preservation :: Archived AS3 works from wonderfl.net

FShape path draw

誰かの為の、SVG path要素を順次描画する簡単?な方法
Get Adobe Flash player
by nutsu 28 Aug 2009
/**
 * Copyright nutsu ( http://wonderfl.net/user/nutsu )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/mxxv
 */

package{
    import frocessing.shape.*;
    import flash.display.*;
    import flash.events.*;
    /**
     * 誰かの為の、SVG path要素を順次描画する簡単?な方法 
     */
    [SWF(width=465,height=465,backgroundColor=0,frameRate=30)]
    public class TestShapePathDraw extends Sprite
    {
        private var sp:FShape;
        private var commands_tmp:Array;
        private var count:int;
        private var ci:int;
        private var d:int = 1;
        
        public function TestShapePathDraw() 
        {
            sp = FShapeSVG.parsePath( getXmlData() );
            sp.styleEnabled = false;
            count = sp.commands.length;
            ci = 0;
            commands_tmp = sp.commands.splice( 0, count );
            addEventListener( Event.ENTER_FRAME, enterframe );
        }
        
        private function enterframe(e:Event):void 
        {
            if( d>0 ){
                sp.commands.push( commands_tmp[ci] );
                ci++;
                if ( ci >= count )
                    d = -1;
            }else {
                sp.commands.pop();
                ci--;
                if ( ci <= 0 )
                    d = 1;
            }
            graphics.clear();
            graphics.lineStyle( 0, 0x999999 );
            sp.drawGraphics( graphics );
        }
        
        private function getXmlData():XML {
            var svg:String = "<path d=\"";
            svg += "M103.515,248.335H93.41l-7.837-31.48h-0.13l-7.708,31.48H67.436l-12.242-46.249h10.169l7.319,31.48h0.129l8.032-31.48";
            svg += "h9.521l7.902,31.869h0.13l7.578-31.869h9.976L103.515,248.335z";
            svg += "M141.346,200.985c14.315,0,22.736,10.688,22.736,24.42c0,13.343-8.421,24.03-22.736,24.03s-22.735-10.688-22.735-24.03";
            svg += "C118.61,211.673,127.031,200.985,141.346,200.985z M141.346,240.886c9.133,0,12.566-7.772,12.566-15.48";
            svg += "c0-8.097-3.433-15.87-12.566-15.87c-9.133,0-12.566,7.773-12.566,15.87C128.78,233.113,132.213,240.886,141.346,240.886z";
            svg += "M171.016,202.086h10.105l19.302,31.027h0.13v-31.027h9.521v46.249h-10.169l-19.238-30.962h-0.129v30.962h-9.522V202.086z";
            svg += "M219.016,202.086h19.95c11.983,0,20.987,7.514,20.987,22.865c0,13.408-6.866,23.383-20.987,23.383h-19.95V202.086z";
            svg += "M229.186,239.784h9.068c5.895,0,11.529-3.627,11.529-13.861c0-9.328-3.238-15.287-13.343-15.287h-7.255V239.784z";
            svg += "M267.018,202.086h34.589v8.55h-24.42v9.91h22.412v7.903h-22.412v11.334h24.938v8.551h-35.106V202.086z";
            svg += "M308.994,202.086h24.938c8.291,0,13.538,5.765,13.538,12.761c0,5.441-2.203,9.521-7.32,11.594v0.13";
            svg += "c4.988,1.295,6.413,6.153,6.737,10.816c0.194,2.915,0.129,8.356,1.942,10.947H338.66c-1.23-2.915-1.102-7.385-1.619-11.076";
            svg += "c-0.713-4.858-2.591-6.996-7.708-6.996h-10.17v18.072h-10.169V202.086z M319.163,223.008h11.142c4.534,0,6.995-1.943,6.995-6.607";
            svg += "c0-4.469-2.461-6.412-6.995-6.412h-11.142V223.008z";
            svg += "M355.764,202.086h32.516v8.55h-22.347v10.688H385.3v7.902h-19.367v19.108h-10.169V202.086z";
            svg += "M394.177, 202.086h10.169v37.698h22.541v8.551h -32.71V202.086z\" />";
            return new XML(svg);
        }
    }
    
}