-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to get a list of elements of SVG #33
Comments
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. |
thank you very much- works perfect ! is there also a way to get al list of filters and styles ? Thanks in advance & regards François |
SVGDocument has a list of definitions. All elements with id goes to definitions, so, your filters will be there, inside filter collections. listDefinitions():Vector.<String> //Returns a list with the ids of all definitions
hasDefinition(id:String):Boolean //Returns if a definition with that id exists
getDefinition(id:String):Object //Returns the definition, it may be a SVGFilterCollection, SVGElement, SVGGradient Styles are also on the SVGDocument. Take a look on those functions: listStyleDeclarations():Vector.<String> //Returns a list of selectors of all style declarations
getStyleDeclaration(selector:String):StyleDeclaration //Get the style declaration Each style declaration is composed by the selector and the properties. rect {
fill: #000;
} Take a look on: https://github.com/LucasLorentz/AS3SVGRenderer/blob/master/SVGRenderer/src/com/lorentz/SVG/data/style/StyleDeclaration.as Btw, just realized a bug on the styles behavior, the library index styleDeclarations by it's selector, so, if you have a SVG with 2 styles block with the same selector, only the last one will work. |
Yesss thank you very much - this works perfect ! now i need a way to add to add filters and patterns - i found document.addDefinition function - is this the way to do is - and if how can i convert the xml-pattern-format into the rigrt object-format ? Thanks in advance & regards François |
Hello,
how can i get a list of elements of an SVG when selecting it.
i can see in com.lorenz.SVG.display.SVG the "numElements" but i dont know how to access them!
Thanks in advance & regards
François
The text was updated successfully, but these errors were encountered: