Search code examples
actionscript-3svgvector-graphicsgenerative-art

AS3 - Export or Save a sprite as SVG or other vector format


I'm working on some generative art projects in AS3, and I keep running into problems with the quality limits of bitmaps. They're not scalable or editable the way vectors are. Is there a class or library that I can use to take a Sprite object's graphics and export them into SVG format? Other common vector formats are also acceptable.

A sample of usage would also be greatly appreciated.

Edit: Note that I'm using FlashDevelop and not Adobe Flash CS. I'm looking for a programmatic solution.


Solution

  • I'm trying to export to svg myself, and finding it a bit surprising that it's so hard to find an svg exporter, since it is pretty much just xml.

    I did come across xgraphics though, it might be helpful.

    in reality you only need the SVG class. It tries to mimic the graphics class in as3, but I found I needed to add a draw polygons class.

        /**
         * graphics
         */
        public function drawPolygon($points:Array):void {
            var $pointsString:String = "";
            for each (var $pt:Point in $points) {
                $pointsString += (" " + $pt.x +"," + $pt.y);
            }
            var xml:XML = new XML('<polygon points="' + $pointsString + '" fill="' + uintToCSS2Color(fillColor) + '" stroke="' + uintToCSS2Color(lineColor) + '" stroke-width="' + strokeWidth + '"/>');
            this.xml.appendChild(xml);
        }
    

    this allows me to make triangles and other shapes by passing an array of points