Thanks, works really well. For anyone else coming down this road, here's two methods of having an action repeat itself while the button is being held. The first method is simple and starts repeating right away, the second method repeats the action only if the button is held for a longer period.
In this sample the function previous_video(), which is on the main timeline, is being triggered. Note that I'm specifying _level0, which isn't the best idea since it makes it so your widget won't work in virtual Chumbies.
on (press) {
_level0.buttonInterval = setInterval(_level0.previous_video, 500); // repeat every 500ms
}
on (release) {
clearInterval(_level0.buttonInterval);
}
on (releaseOutside) {
clearInterval(_level0.buttonInterval);
}
The above works well, but I found it hard to get precise control. So this other method allows an action to be triggered when first pressed, and then repeated only if the button is held for awhile.
This block of code is located in the button:
on (press) {
_level0.previous_video(); // execute the function immediately
_level0.buttonTimeout = setTimeout(_level0.previous_video_changer, 750); // start repeating if button is held more than 750ms
}
on (release) {
clearInterval(_level0.buttonInterval);
clearInterval(_level0.buttonTimeout);
}
on (releaseOutside) {
clearInterval(_level0.buttonInterval);
clearInterval(_level0.buttonTimeout);
}
This block of code is located on the main timeline:
function next_video_changer() {
_level0.buttonInterval = setInterval( _level0.next_video, 50 ); // repeat the action every 50ms
}
In the above recipe, the previous_video() function is triggered immediately when the button is pressed, but if the button is held for longer than 500ms, it triggers the next_video_changer() function, which launches an interval to trigger the next_video() function every 50ms.
You can see the latter method in action in my ChumbySpy widget:
http://www.chumby.com/guide/widget/ChumbySpy
Click the ? icon at top right to access the settings, then turn off "Randomize" and turn on "Show URL & Channel", then click the left and right edges of the screen to advance to previous and next camera. Note how if you hold your finger on the screen the cameras advance quickly.