Forum Moderators: open

Message Too Old, No Replies

script to rotate swf flash FILES on browser refresh

how to rotate swf flash banner FILES on refresh

         

setheus

5:08 pm on Jun 17, 2006 (gmt 0)

10+ Year Member



I have 3 small swf flash movies. I want to rotate them whenever a visitor refresh a page. So if you go to my website you watch the movie and when you go back again the next minute, hour or day, you'll see a different movie.

I know there's a code to rotate images but i can't find a script to rotate swf files.

Please DO NOT post a flash code or anything to use on the flash or swish software. I'm looking for a script to put on my HTML files.

oxbaker

3:22 pm on Jun 19, 2006 (gmt 0)

10+ Year Member



use javascript.

MAke an array of links to the different .swf movies. on Page load grab a random number from the array and display the link in that index position.

hth,
mcm

setheus

5:16 pm on Jun 22, 2006 (gmt 0)

10+ Year Member



im sorry i dont know anything about javascript. could anyone just please post a code?

WilMoya

3:52 pm on Aug 7, 2006 (gmt 0)

10+ Year Member



I use a script on my site to rotate swf files on page refresh. It works great on IE but doesn't work on Firefox. Maybe another forum member can find a solution to the Firefox issue. I've tried but haven't been successful. Here's a sample of the script:


<script language="JavaScript">

// Generate a Random Number
var randomnumber = Math.round(Math.random()*3);

// Select a movie and execute the corresponding function
if (randomnumber == 1)

{movie1();}

else if (randomnumber == 2)

{movie2();}

else {movie3();}

//Functions to write out the correct flash movie resource.

function movie1(){
document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0\" width=\"770\" height=\"150\"><param name=movie value=\"../flash/banner1.swf\"><param name=loop value=false><param name=quality value=high><embed src=\"movie1.swf\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"300\" height=\"200\"></embed></object>")
}

function movie2(){
document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0\" width=\"770\" height=\"150\"><param name=movie value=\"../flash/banner2.swf\"><param name=loop value=false><param name=quality value=high><embed src=\"movie2.swf\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"300\" height=\"200\"></embed></object>")
}

function movie3(){
document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0\" width=\"770\" height=\"150\"><param name=movie value=\"../flash/banner3.swf\"><param name=loop value=false><param name=quality value=high><embed src=\"movie3.swf\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"300\" height=\"200\"></embed></object>")
}

</script>

Hope this helps. You have to modify the number of swf files you are going to rotate as well as the path to the files to match your paths.

monkeythumpa

7:42 pm on Aug 7, 2006 (gmt 0)

10+ Year Member



I can post one in PHP if you use that, it will decrease the amount of code you have to download.

WilMoya

4:01 am on Aug 9, 2006 (gmt 0)

10+ Year Member



Sure, post it please.

Wil

gellydonut

10:47 pm on Aug 18, 2006 (gmt 0)

10+ Year Member



In PHP, if you name your files movie1.swf, movie2.swf and movie3.swf, this script will load a randomly selected .swf on each reload:

<?
$r=rand(1,3);
?>
<object type="application/x-shockwave-flash" data="movie<?=$r?>.swf" width="300" height="40">
<param name="movie" value="movie<?=$r?>.swf" />
</object>

rocknbil

6:03 am on Aug 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is all good. Just two things:

You can apply the same simple principles in the last post to the javascript solution. Just write out the code once and change the src. That will work.

The one bad thing with both of these - especially if you only have three or four files - is that in all cases random can "randomly" pick the same image 3, 5, even 10 times in a row.

You need to store whatever the last image/flash was somewhere so it re-picks if that one is picked, or temporarily remove the "last flash" from your array.

WilMoya

5:16 am on Aug 26, 2006 (gmt 0)

10+ Year Member



You can also use the javascript above by saving it as a separate js file and then link to it from your html.

olti

1:53 am on Feb 20, 2008 (gmt 0)

10+ Year Member



Anyone here that can make WilMoya's script to work with Firefox too?

PS: Sorry for updating this old thread, but I need this script.