I have a .swf banner embeded on my xhtml and I need it to replay after 20 seconds so if the user is still watching that page he will see the animation again. It needs to be a loop or something so the animation will play again 20 seconds after finished over and over again. Can this be achieved with javascript?
Thanks!
Assuming you have a unique id for the flash player you could simply do this:
var player = document.getElementById("playerID");
var movieLength = 10000; // in ms, change this as needed
var delay = 20000; // in ms
function playMovie() {
player.play();
window.setTimeout(playMovie, movieLength + delay);
};
playMovie(); // Assuming it doesn't start automatically.
This calls the play()
function on the player every 20 seconds (plus movie length and delay).
It can, but it seems to make more sense to just tell the <object/embed>
tag to loop. http://helpx.adobe.com/flash/kb/flash-object-embed-tag-attributes.html
If you don't have access to the Flash source (to add 20 seconds of blank to the end of the movie), then yes, you would need JS.
Figure out how long the movie is, in seconds. Multiply that times 1000, and add 20000 to it.
Take that number and put it in here:
var timing = 30000; //whatever the 20000 + the number you found before was, put it here
$(function() {
window.setInterval(function() {
$("#myPlayer").get(0).play();
}, timing);
});