Change animation mode through scripting

HenriAugusto shared this question 8 years ago
Answered

Hi everybody!


I'm using javascript to create a slider.


    for(var i=1;i<20;i++)

    ggbApplet.evalCommand("rotation_{"+i+"}=Slider[ 0, 2*pi, 0.01, "+i+", 50 ]");


Now i want to change, through javascript, the animation type of this slider (oscillating/increasing/decreasing). But i didn't found any command that allowed me to do it. In this website they say this is not possible. This statement is true?


In that case there is anyway i can do this through evalXML() command? I didn't found any explanation on how to use the evalXML() command. Should i use ggbApplet.evalXML("string here") in my code?


Also, after creating the sliders, my "rotation" sliders looks like this in my xml. How can i refer to "animation type" and change if from 0 to 1 using evalXML?


    <element type="numeric" label="rotation_{1}">

    <value val="0.0"/>

    <show object="true" label="true"/>

    <condition showObject="false"/>

    <objColor r="0" g="0" b="0" alpha="0.1"/>

    <layer val="0"/>

    <labelMode val="1"/>

    <slider min="0" max="6.283185307179586" absoluteScreenLocation="true" width="50.0" x="30.0" y="170.0" fixed="false" horizontal="true"/>

    <lineStyle thickness="10" type="0" typeHidden="1"/>

    <animation step="0.01" speed="1" type="0" playing="false"/>


Should i use something like this?


    ggbApplet.evalXML("rotation_{1} animation type="1"")


Well, let me resume to make things simpler:

1) Is it possible to change an objects animation mode (oscillating/increasing/decreasing) through normal scripting commands on javascript?

2)If answer to 1 is "no", then how can i do it with evalXML? It needs to be done on the fly, through the clicking of a button.


Thanks a lot for your kind attention,

Henri.

Comments (1)

photo
1

I don't know how it didn't came in my forum search. This should be a sticky! :p Thanks a lot Noel Lambert!


Well, i managed to use mooffie's script successfully in my .ggb. Let me just note something in case other newcomers to javascript (such as me) finds this. To make it work inside "for's", you have to use ' symbol for strings, instead of " symbol. So instead of the common "stringhere"+i+"stringhere" you have to use 'stringhere'+i+'stringhere'.


    for(var i=1;i<20;i++)

    setXmlProperty('rot_{'+i+'}', '<animation step="0.01" speed="'+i+'" type="1" playing="false"/>', true);


That might sound silly but it gave me some headache. I wish i could write this in a collapsible box, might as well suggest that.


As much easy it may seem to use a ready-to-go script like mooffie's, it makes me wander if is it really necessary all of that work just to change a simple object property.

© 2022 International GeoGebra Institute