Skip to main content
Participating Frequently
December 28, 2021
Answered

Set speed rotation with text input filed in html5

  • December 28, 2021
  • 1 reply
  • 717 views

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 has been closed for replies.
    Correct answer JoãoCésar17023019

    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

    1 reply

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    December 28, 2021

    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

    NIna12Author
    Participating Frequently
    December 28, 2021

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

    JoãoCésar17023019
    Community Expert
    Community Expert
    December 28, 2021

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