-
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 filling element with color or image? #32
Comments
And in continuation of stupid questions - how can I find the x and y of individual elements of the document? |
Hello. For a coloring book, you may listen to mouse events like hover and find the right svg element that is hovered. You can use the method DisplayUtils.getSVGElement, or traverse up the display tree looking for elements that match your conditions (ie: only path elements). A nice example is the test flex application: https://github.com/LucasLorentz/AS3SVGRenderer/blob/master/SVGRendererFlexTest/src/SVGRendererTest.mxml It allows selecting an element of the svg, and highlights it. After selecting a svg element, you may allow changing its properties (fill-color, stroke-color, and so on). To change the fill color of a element, you must set the style attribute: element.style.setProperty("fill-color", "#FF0000"); |
To find the x and y, you may simply get the element bounds using the flash method getBounds. |
The library tries to allow editing all svg properties directly on the svg element (that is added to the display tree). It also render the element again after those changes. |
Thank your very much for so detailed answer. I'll try it. |
Hi! |
Trying to set style - byt it has no result. Maybe i sould do anything else? element.style.setProperty("fill", "#FF0000"); I didn't fully understand this: "After selecting a svg element, you may allow changing its properties (fill-color, stroke-color, and so on)." How I can allow it? Capturing mouse events: svg.addEventListener(MouseEvent.MOUSE_OVER, svg_mouseOverHandler);
svg.addEventListener(MouseEvent.MOUSE_OUT, svg_mouseOutHandler);
svg.addEventListener(MouseEvent.CLICK, svgGroup_clickHandler);
protected function svg_clickHandler(e:MouseEvent):void {
selectedElement = DisplayUtils.getSVGElement(e.target as DisplayObject);
}
protected function svg_mouseOverHandler(e:MouseEvent):void {
var svgElement:SVGElement = DisplayUtils.getSVGElement(e.target as DisplayObject);
if(svgElement){
svgElement.transform.colorTransform = new ColorTransform(1, 1, 1, 1, 0x66, 0x66, 0x66);
}
}
protected function svg_mouseOutHandler(e:MouseEvent):void {
var svgElement:SVGElement = DisplayUtils.getSVGElement(e.target as DisplayObject);
if(svgElement && svgElement != _selectedElement){
svgElement.transform.colorTransform = new ColorTransform();
}
} And secon. Then I trying to convert SVGElement to bitmap(with BitmapData.draw()), it looks, like a result scaling to very small. Where i'm wrong?) svg.addEventListener(SVGEvent.RENDERED, renderedEventHandler); To solve the size problem, you can also pass a scaling transform matrix to the BitmapData.draw method. My english isn't very good. That's why you didn't understand me. :-) |
Hello! 2013/8/30 LucasLorentz [email protected]
|
Hi, it's me again :-) I have another question: Can I somehow use the
|
Hi, it's me again :-) I have another question: Can I somehow use the |
Hello!
Thank you for this library.
I'm trying to use it to create "coloring-book", and need your help)
How can I fill some element with color or bitmap?
Thank you for your attention!
The text was updated successfully, but these errors were encountered: