Yeah, you could combine this into one script. @Photics example is good but uses a different construction for the sliders. The approach I would take is just to have the function get all the values from both sliders and then set them all at the same time. Slightly inefficient, but I don’t think it would matter. I assume you’re going to want a new element with the ID “sum
” that will display the total. The code would look like this:
// gather amounts
var amount1 = hypeDocument.currentTimeInTimelineNamed('slider 1');
var amount2 = hypeDocument.currentTimeInTimelineNamed('slider 2');
// calculate sum
var sum = (amount1 + amount2);
// get elements
var amount1Element = hypeDocument.getElementById('amount1');
var amount2Element = hypeDocument.getElementById('amount2');
var sumElement = hypeDocument.getElementById('sum');
// set elements to new values
amount1Element.innerHTML = amount1.toFixed(0);
amount2Element.innerHTML = amount2.toFixed(0);
sumElement.innerHTML = sum.toFixed(0);
You can see it in action here:
adding_sliders_sum.hype.zip (22.3 KB)
One other thing - the sliders aren’t really moving 1:1 with the mouse. A On Drag to Control Timeline at 100% speed means that for every 100px dragged, the timeline will advance by 1s. Your elements are moving from 37px to 504px = 467px total in 10s. Therefore the speed value should be 10/467 = 214% for a 1:1 match. I also made this change.