You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Gurleen Randhawa <gu...@TreesforLife.org> on 2004/01/21 22:46:53 UTC
Not able to run scripts in Batik
I tried the sample script provided on the Batik web site , but I got the following error
SVG Error : 'showDialog' not defined
This is the code that I wrote
// Root Element
SVGSVGElement currentRoot = currentSVGDoc.getRootElement()
// create the script
Element elem = currentSVGDoc.createElementNS(null, "script");
elem.setAttributeNS(null, "type","text/ecmascript");
Text text = new GenericText("function showDialog(msg) {alert(msg);} " , (AbstractDocument)svgComp.getSVGDocument());
elem.appendChild(text);
currentRoot.appendChild(elem);
// create the circle element
Element circle = currentSVGDoc.createElementNS(SVGConstants.SVG_NAMESPACE_URI, "circle");
circle.setAttributeNS(null, "cx", "137.5");
circle.setAttributeNS(null, "r", "20");
circle.setAttributeNS(null, "cy", "110");
circle.setAttributeNS(null, "style", "fill:crimson");
circle.setAttributeNS(null, "onmouseover","showDialog('onmousemove')");
currentRoot.appendChild(circle);
The sample script that I used is shown here
http://xml.apache.org/batik/scripting.html#howToUseScripting
Thanks
Re: Not able to run scripts in Batik
Posted by Thomas DeWeese <Th...@Kodak.com>.
Gurleen Randhawa wrote:
>
> I tried the sample script provided on the Batik web site , but I got
> the following error
We do not eval script elements when they are added to the document
(the logic here is a little fuzzy but goes something like - what would
we do if you 'removed' one - best to say they aren't 'dynamic'
entities).
You can eval script from Java fairly easily (psudo code):
try {
String myScript = ...;
Interpreter i=bridgeContext.getInterpreter("text/ecmascript");
i.evaluate(myScript);
} catch (InterpreterException ie)
{ ... }
You can get the BridgeContext from the JSVGCanvas. Of course you
need to make sure you do this from the UpdateManager thread.
>
> SVG Error : 'showDialog' not defined
>
> This is the code that I wrote
>
> // Root Element
>
> SVGSVGElement currentRoot = currentSVGDoc.getRootElement()
>
> // create the script
> Element elem = currentSVGDoc.createElementNS(null, "script");
> elem.setAttributeNS(null, "type","text/ecmascript");
> Text text = new GenericText("function showDialog(msg) {alert(msg);} " ,
> (AbstractDocument)svgComp.getSVGDocument());
> elem.appendChild(text);
> currentRoot.appendChild(elem);
>
>
> // create the circle element
> Element circle =
> currentSVGDoc.createElementNS(SVGConstants.SVG_NAMESPACE_URI, "circle");
> circle.setAttributeNS(null, "cx", "137.5");
> circle.setAttributeNS(null, "r", "20");
> circle.setAttributeNS(null, "cy", "110");
> circle.setAttributeNS(null, "style", "fill:crimson");
> circle.setAttributeNS(null, "onmouseover","showDialog('onmousemove')");
> currentRoot.appendChild(circle);
>
> The sample script that I used is shown here
>
> http://xml.apache.org/batik/scripting.html#howToUseScripting
>
>
>
> Thanks
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org