Skip to main content
Participating Frequently
Dec 28, 2021 7:25 AM UTC
Answered

Set speed rotation with text input filed in html5

Hi everyone, it's me again😊

 

How can I make a button rotate another object, like this:

 

There is an object, button and input text field:

when I put the number in the input text field and then click the button, it will effect on rotation speed.  Higher numbers that user type in the input text will cause faster rotation. But, in other case, i want to set the object rotate only 10 times not continously.

 

How can I do this using html5? Can anyone tell me the code?

Thanks in advance!

Have a nice day

Sorry, I'm not good in English. Hope you can understand my question😊

    This topic is closed to new replies. Start a new post to keep the conversation going.
    JoãoCésar17023019
    JoãoCésar17023019Correct answer
    Community Expert
    Dec 28, 2021 11:31 AM UTC

    Hi.

     

    Here is a suggestion to get you started:

    var root = this;
    var yourRotatingInstance = root.yourRotatingInstance;
    var yourButton = root.yourButton;
    var rotationSpeed = 1;
    
    createjs.Ticker.on("tick", function()
    {
    	yourRotatingInstance.rotation += rotationSpeed;
    });
    
    yourButton.on("click", function()
    {
    	yourInput = document.getElementById("yourInput");
    	
    	if (yourInput.value && !isNaN(yourInput.value))
    		rotationSpeed = Number(yourInput.value);
    });

     

    I hope this helps.

     

    Regards,

    JC

    9 replies

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    Dec 28, 2021 11:31 AM UTC

    Hi.

     

    Here is a suggestion to get you started:

    var root = this;
    var yourRotatingInstance = root.yourRotatingInstance;
    var yourButton = root.yourButton;
    var rotationSpeed = 1;
    
    createjs.Ticker.on("tick", function()
    {
    	yourRotatingInstance.rotation += rotationSpeed;
    });
    
    yourButton.on("click", function()
    {
    	yourInput = document.getElementById("yourInput");
    	
    	if (yourInput.value && !isNaN(yourInput.value))
    		rotationSpeed = Number(yourInput.value);
    });

     

    I hope this helps.

     

    Regards,

    JC

    Translate
    NIna12Author
    Participating Frequently
    Dec 28, 2021 1:20 PM UTC

    Sorry it's not working. Whenever I change the number in textinput, the speed rotation is still the same

    Translate
    JoãoCésar17023019
    Community Expert
    Community Expert
    Dec 28, 2021 1:26 PM UTC

    You said you wanted the change to be applied when the button is clicked.

    Translate