Cameron McCormack schrieb:
Modifying the attributes of an animation element while it is in the
document will not change the animation.  This is half bug, half
underdefined-ness in the SVG specification.  What will work, though, is
removing the animation element from the document to stop it, and
re-inserting it when you want to start it again.

Alternatively, you could use the beginElement() and endElement() methods
on animateColorE (you’ll need to cast it to ElementTimeControl to get
those methods).  That will start or stop the animation.  (Technically,
it’s like adding an entry to the begin="" or end="" attribute with the
current time.)
thanks very much for your answer!
however, removing the element is the last thing I want to do, because it might cause concurrent exception if any related thread doesn't work in time, and most of the time they don't... I've tried the elementTimeControl and it works perfectly, remaining one problem though:

Actually I want the animation only start if I press the button, which means it is stopped at first as the svg is loaded. But if I do the endElement() directly after I initiate the animateColorE like this:

animateColorE.setAttributeNS(null, SVGConstants.SVG_REPEAT_COUNT_ATTRIBUTE, "indefinite");
       ((ElementTimeControl)animateColorE).endElement();

I would get a null pointer exception when I start the program:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.apache.batik.dom.svg.SVGOMAnimationElement.endElement(SVGOMAnimationElement.java:158) at rotationTest.ColorChangingAndStopping.initBall(ColorChangingAndStopping.java:124) at rotationTest.ColorChangingAndStopping.<init>(ColorChangingAndStopping.java:75) at rotationTest.ColorChangingAndStopping$4.run(ColorChangingAndStopping.java:131)
   at java.awt.event.InvocationEvent.dispatch(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)

I suppose the animateColorE is not properly initiated yet when I tried to stop it. so the question is, where is the right place I should do the endElement() if I want the animation remaining stopped firstly, or when is animateColorE completely initiated so that I could use the endElement on it to stop it in time before it shows itself?

thanks very much in advance,
Cui

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to