Skip to main content
Inspiring
May 31, 2018
Answered

Slider to control timeline

  • May 31, 2018
  • 5 replies
  • 12551 views

Hi there,

I have checked a few posts about controlling the timeline with a slider but I am afraid they may be a bit too advanced for me.

Would anyone recommend a post or a resource which explains the simplest way to have a slider that controls the timeline.

Just the simplest case.

Thank you in advance

B

This topic has been closed for replies.
Correct answer JoãoCésar17023019

// UPDATE (10/26/2018): improved version that takes into account responsive settings, drag offset and frame to position precision.

The download link is the same.

this.button.on("mousedown", function(e)

{

     e.target.offsetX = (e.stageX / stage.scaleX) - e.target.x;

}.bind(this));

this.button.on("pressmove", function(e)

{

     e.target.x = this.clamp((e.stageX / stage.scaleX) - e.target.offsetX, this.bar.x, this.bar.x + this.bar.nominalBounds.width);

     this.setProportion();

}.bind(this));

this.setProportion = function()

{

     var prop = (this.button.x - this.bar.x) / this.bar.nominalBounds.width;

     this.txt.x = this.button.x;

     this.txt.text = Math.round(prop * 100) + "%";

     this.bar.gotoAndStop(Math.floor(this.bar.timeline.duration * prop));

}.bind(this);

this.clamp = function(value, min, max)

{

     if (value < min)

          return min;

     else if (value > max)

          return max;

     else

          return value;

}

setTimeout(this.setProportion, 0);

// UPDATE END

Hi.

This is the simplest slider I can think of. Please notice two things:

- The highlight is a timeline animation so it won't necessarlity match the position of the slider button. But the frames are set proportionally as expected.

- I used setTimeout to call the proportion function in the beginning to make sure the bar timeline will be ready when needed.

Preview:

JavaScript code:

this.button.on("pressmove", function(e)

{

    e.target.x = this.clamp(e.stageX, this.bar.x, this.bar.x + this.bar.nominalBounds.width);  

    this.setProportion();

}.bind(this));

this.setProportion = function()

{

    var prop = (this.button.x - this.bar.x) / this.bar.nominalBounds.width;

  

    this.txt.x = this.button.x;

    this.txt.text = Math.round(prop * 100) + "%";

    this.bar.gotoAndStop(Math.floor(this.bar.timeline.duration * prop));

}.bind(this);

this.clamp = function(value, min, max)

{

    if (value < min)

        return min;

    else if (value > max)

        return max;

    else

        return value;

}

setTimeout(this.setProportion, 0);

FLA download:

animate_cc_html5_simple_slider.zip - Google Drive

I hope it helps.

Regards,

JC

5 replies

Participating Frequently
November 18, 2022

Maybe you should go to the help of the website to download the as Help manual

Participant
November 18, 2022

What a useless response.

kglad
Community Expert
Community Expert
November 18, 2022

@Richard23620971p1yo,

 

try to refrain from responding to trolls. it leads no where beneficial.

 

do you have a questions about your original or subsequent posts?

Participant
February 15, 2021

Any ideas for how I could use this slider to make a more advanced master controller plugin for Animate which can frame pick and refer to instances on the timeline in graphic symbols? Say for example if I wanted to rig up a 360 head turn using drawn keyframes and morphed shapes that the slider could control on an xyz grid which selects the instances and frames within the symbol?

berzins
Inspiring
December 4, 2020

This slider is built excellent - I have not found anything better. All my compliments.
I duplicated it, cause I needed two sliders in one frame and I got two numbers, generated by sliders (I removed % from text field). Given names are txt1 and txt2 ("txt" in the original script).
I'm stuck to use those numbers now to make some calculations using them. Can anyone give a hint?

berzins
Inspiring
December 4, 2020

OK ... I figured out it by myself, how to link those numbers to make calculations.

What  is still not solved is the Range of the sliders and numbers.
They are now percents. How to make them "from1 to30", for example?

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
June 1, 2018

// UPDATE (10/26/2018): improved version that takes into account responsive settings, drag offset and frame to position precision.

The download link is the same.

this.button.on("mousedown", function(e)

{

     e.target.offsetX = (e.stageX / stage.scaleX) - e.target.x;

}.bind(this));

this.button.on("pressmove", function(e)

{

     e.target.x = this.clamp((e.stageX / stage.scaleX) - e.target.offsetX, this.bar.x, this.bar.x + this.bar.nominalBounds.width);

     this.setProportion();

}.bind(this));

this.setProportion = function()

{

     var prop = (this.button.x - this.bar.x) / this.bar.nominalBounds.width;

     this.txt.x = this.button.x;

     this.txt.text = Math.round(prop * 100) + "%";

     this.bar.gotoAndStop(Math.floor(this.bar.timeline.duration * prop));

}.bind(this);

this.clamp = function(value, min, max)

{

     if (value < min)

          return min;

     else if (value > max)

          return max;

     else

          return value;

}

setTimeout(this.setProportion, 0);

// UPDATE END

Hi.

This is the simplest slider I can think of. Please notice two things:

- The highlight is a timeline animation so it won't necessarlity match the position of the slider button. But the frames are set proportionally as expected.

- I used setTimeout to call the proportion function in the beginning to make sure the bar timeline will be ready when needed.

Preview:

JavaScript code:

this.button.on("pressmove", function(e)

{

    e.target.x = this.clamp(e.stageX, this.bar.x, this.bar.x + this.bar.nominalBounds.width);  

    this.setProportion();

}.bind(this));

this.setProportion = function()

{

    var prop = (this.button.x - this.bar.x) / this.bar.nominalBounds.width;

  

    this.txt.x = this.button.x;

    this.txt.text = Math.round(prop * 100) + "%";

    this.bar.gotoAndStop(Math.floor(this.bar.timeline.duration * prop));

}.bind(this);

this.clamp = function(value, min, max)

{

    if (value < min)

        return min;

    else if (value > max)

        return max;

    else

        return value;

}

setTimeout(this.setProportion, 0);

FLA download:

animate_cc_html5_simple_slider.zip - Google Drive

I hope it helps.

Regards,

JC

Inspiring
June 1, 2018

Wow, that is really impressive. Thank you so much.

I will try my best to understand as much as I can but a lot of that is beyond my knowledge.

I can see where you reference the button and the dynamic text, but the rest ...

Would you have a link to where I can learn a bit more about the expressions you used?

Thank you once again.

JoãoCésar17023019
Community Expert
Community Expert
June 1, 2018

Excellent! I'm sure you're gonna understand all of this very fast.

You can take at look at CreateJS's official docs and especially in this mouse interactions tutorials:

EaselJS Tutorial: Mouse Interaction

And you can also look for general JavaScript tutorials on Lynda.com and YouTube, for example.

kglad
Community Expert
Community Expert
May 31, 2018

html5 or as3?

component or custom movieclip?

what code have your tried?

Inspiring
May 31, 2018

Thanks for your reply. Sorry I did not specify.

It is HTML 5, any idea about the simplest slider that would change a variable or/and a frame number when sliding would be welcome.

kglad
Community Expert
Community Expert
May 31, 2018

there is no slider component (yet) for html5 so you'll need to make your own.

create a movieclip that displays the range

add a movieclip that will be dragged and indicate the location along the range

add a mousedown listener for the indicator that triggers a ticker loop

in the ticker listener check the indicators location and use that in your movieclip goto