Skip to main content
Participating Frequently
October 12, 2022
Question

HTML5 button that changes speed of movie clip animation

  • October 12, 2022
  • 1 reply
  • 535 views

Hi. I'm very new to coding so please bear with me. I have a movieclip of spinning arrows. I need to create a button that speeds up the movieclip, say around two times the speed. Is there a suitable code I could use for this? Thanks.

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    October 12, 2022

    yes, call mc_startF (passing a movieclip reference and frame rate) to start the play.  call mc_stopF (passing a movieclip reference to stop the play).

     

    function mc_startF(mc,framerate){
    clearInterval(mc.I);
    mc.stop();
    mc.I = setInterval(f.bind(mc), 1000/framerate);
    }
    function mc_stopF(mc){
    clearInterval(mc.I);
    }


    function f(){
    if(this.currentFrame==this.totalFrames-1){
    this.gotoAndStop(0);
    }
    this.gotoAndStop(this.currentFrame+1);
    }

    Participating Frequently
    October 12, 2022

    Hi Kglad,

    Thanks for this response. Please forgive my ignorance here, but if my movie clip is called Arrows, and the button in question is called Button01, and the starting framerate is 24 fps, and I want to double this speed when I click the button, what would the code be? Also, I actually want to click a different button to set the frame rate back to normal, so I'm assuming the mc.stopF part would be in the actions of this second button and not the first?

    kglad
    Community Expert
    Community Expert
    October 12, 2022

    this.Button01.addEventListener("click",clickF.bind(this));

     

    function clickF(){

    mc_startF(this.Arrows,48);

    }