Skip to content
This repository has been archived by the owner on May 15, 2022. It is now read-only.

Shape Export

claus edited this page Jan 25, 2012 · 21 revisions

With as3swf you can export any shape contained in a SWF, including font shapes of embedded fonts, to virtually any other format. You can redraw shapes with Actionscript at runtime, or export source code (e.g. Actionscript, Objective-C, SVG, Degrafa, FXG), or do whatever you feel like doing with it. Reuse your existing Flash vector art on other platforms.


Shape Exporter classes

Currently available shape exporters are:

- AS3ShapeExporter (ActionScript Drawing API code generator)
- AS3GraphicsDataShapeExporter (ActionScript 3 IGraphicsObjects)
- CoreGraphicsShapeExporter (Objective-C Quartz/CoreGraphics code generator)
- FXGShapeExporter
- SVGShapeExporter
- JSCanvasShapeExporter (JavaScript Canvas code generator)
- JSONShapeExporter (JSON generator)


Usage

public function ShapeExport() {
  var request:URLRequest = new URLRequest("any.swf");
  var loader:URLLoader = new URLLoader();
  loader.dataFormat = URLLoaderDataFormat.BINARY;
  loader.addEventListener(Event.COMPLETE, completeHandler);
  loader.load(request);
}
private function completeHandler(e:Event):void {
  // Parse SWF
  var swf:SWF = new SWF(URLLoader(e.target).data as ByteArray);
  // Create exporter (in this case the AS3 Drawing API code generator)
  var doc:AS3ShapeExporter = new AS3ShapeExporter(swf);
  // Loop over all tags
  for (var i:uint = 0; i < swf.tags.length; i++) {
    var tag:ITag = swf.tags[i];
    // Check if tag is a DefineShape
    if (tag is TagDefineShape) {
      // Export shape
      TagDefineShape(tag).export(doc);
      trace(doc.actionScript);
    }
  }
}

Shape export is enabled for DefineShape, DefineMorphShape and DefineFont tags.

- TagDefineShape: export(handler:IShapeExporter)
- TagDefineMorphShape: export(handler:IShapeExporter, ratio:Number)
- TagDefineFont: export(handler:IShapeExporter, glyphIndex:uint)

The export() methods expect an instance of a SAX-style callback handler, implementing IShapeExporter (if no such handler is provided, they use DefaultShapeExporter, which does nothing).


Limitations

- bitmap fills not supported yet
- missing convenience methods for bitmap export (to be used in combination with bitmap fills)

I’m working on it.

Clone this wiki locally