Replay a .swf after 20 seconds

Go To StackoverFlow.com

0

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!

2012-04-04 19:15
by San Rabid


1

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).

2012-04-04 19:20
by kiswa
This will replay it every twenty seconds, you need to add the length of the movie itself. Also, this will only do it onc - Juan Mendes 2012-04-04 19:24
Edited for infinte replay. Thanks! Not knowing movie length, I leave that up to the asker - kiswa 2012-04-04 20:03


1

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.

2012-04-04 19:25
by Juan Mendes
Unfortunately I don't have access to the .fla file. The client had this .swf since who knows when... So I need to use a js solution - San Rabid 2012-04-04 19:30
Then use kiswa's suggestion, along with the comments I posted by the answer - Juan Mendes 2012-04-04 19:32


0

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);
});
2012-04-04 19:37
by Jordan
Ads