Skip to content
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

Open
dezomer opened this issue Oct 19, 2013 · 4 comments
Open

how to get a list of elements of SVG #33

dezomer opened this issue Oct 19, 2013 · 4 comments

Comments

@dezomer
Copy link

dezomer commented Oct 19, 2013

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

@lucaslorentz
Copy link
Owner

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.

@dezomer
Copy link
Author

dezomer commented Oct 21, 2013

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

@dezomer dezomer closed this as completed Oct 21, 2013
@dezomer dezomer reopened this Oct 21, 2013
@lucaslorentz
Copy link
Owner

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

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.

@dezomer
Copy link
Author

dezomer commented Oct 30, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants