-
Notifications
You must be signed in to change notification settings - Fork 27
AS3 only example, setting availableWidth and availableHeight
LucasLorentz edited this page Feb 24, 2013
·
1 revision
Some SVG files don't have fixed size, they scales to the available area.
To understand that, open the gradients1.svg file on a browser, and resize the browser.
You can use the "availableWidth" and "availableHeight" properties to control the available area.
More information on:
http://www.w3.org/TR/SVG/coords.html#ViewportSpace
http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute
http://www.w3.org/TR/SVG/coords.html#PreserveAspectRatioAttribute
Example:
package {
import flash.display.MovieClip;
import flash.geom.Rectangle;
import flash.utils.ByteArray;
import lorentz.SVG.display.SVGDocument;
import lorentz.SVG.events.SVGEvent;
import lorentz.processing.ProcessExecutor;
[SWF(width="800", height="600")]
public class SVGTest extends MovieClip {
public function SVGTest() {
//Starts the asynchronous processor
ProcessExecutor.instance.initialize(stage);
//Creates a document
var svgDocument:SVGDocument=new SVGDocument();
var widthIWant:Number = 400;
var heightIWant:Number = 400;
svgDocument.availableWidth = widthIWant;
svgDocument.availableHeight = heightIWant;
//Draw a rect to show the swf area
graphics.beginFill(0xEEEEEE);
graphics.drawRect(0, 0, widthIWant, heightIWant);
//Add the document to the screen
addChild(svgDocument);
//Parses the svg string
svgDocument.parse(getSVGString());
}
[Embed(source="gradients1.svg", mimeType="application/octet-stream")]
private var TextClass:Class;
private function getSVGString():String {
var byteArray:ByteArray=new TextClass() as ByteArray;
return byteArray.readUTFBytes(byteArray.length);
}
}
}