-
Notifications
You must be signed in to change notification settings - Fork 27
Documentation
Interacting with SVG content
The library is asynchronous, and you must wait the parse completes before interacting with SVG content. It would be:
svgDocument.addEventListener(SVGEvent.PARSE_COMPLETE, function(e:SVGEvent):void {
//Now you can interact with the content
});
Accessing Elements
Every svg container has the methods: getElementAt, and numElements. Using that you can iterate through the children of an element.
If you want to do that on a SVGDocument, it would be:
for(var i = 0; i < document.numElements; i++){
var element = document.getElementAt(i);
//do something with element
}
It is like a tree, not a flat list. To visit all elements, you will need to do a recursive function.
SVGDocument has a list of definitions. All elements with id goes to definitions, so, your filters will be there, inside filter collections. You can use the following functions to retrieve them
//Returns a list with the ids of all definitions
listDefinitions():Vector.<String>
//Returns if a definition with that id exist
hasDefinition(id:String):Boolean
//Returns the definition, it may be a SVGFilterCollection, SVGElement, SVGGradient
getDefinition(id:String):Object
Styles are also on the SVGDocument. Take a look on those functions:
//Returns a list of selectors of all style declarations
listStyleDeclarations():Vector.<String>
//Get the style declaration
getStyleDeclaration(selector:String):StyleDeclaration
Each style declaration is composed by the selector and the properties.
rect {
fill: #000;
}
Take a look on: StyleDeclaration
Changing Properties
Example:
var rect: SVGRect = svgDocument.getDefinition("myRectId");
rect.svgWidth = "20%";
rect.style.setProperty("fill", "#000");
The library will detect the changes and render again only the affected parts.
Editing SVG Test
Not currently supported. The library has TextField and TLF text renderers. Both would support text editing with some minor changes.
If you have a very simple text element. You could create a custom text renderer, based on the file: TLFSVGTextDrawer
Changing the SelectionManager to EditManager, on line:
textFlow.interactionManager = new SelectionManager();
But to make it work with tspan, line breaks, formatting and so on. You would need to edit text on a rich text editor, maybe made with TLF too, and then generate tspans, texts, with pre-calculated positions.