Forum Moderators: open
I want to have my page display a random Flash movie (.swf) every time the page loads (I have 4 total movies). Had I not been using the SWFObject, really any random javascript code would work, but I'm having some difficulty using javascript within javascript. I'm not going to show you the code that I had, since it doesn't work anyways, and I don't need to muddy the situation. Below I have pasted the code I am using to generate my Flash:
<script type="text/javascript" src="_scripts/flashobject.js"> </script><div id="flashcontent" style="width:100%;height:348px"></div>
<script type="text/javascript">
var fo = new FlashObject("flash/header.swf", "animationName", "100%", "348", "8", "");
fo.addParam("allowScriptAccess", "sameDomain");
fo.addParam("quality", "high");
fo.addParam("scale", "noscale");
fo.addParam("loop", "false");
fo.write("flashcontent");
</script>
Thanks in advance for any help or advice you can give,
Matt
If you can control the naming of your flash files (and I assume you can) name them sequentially (flash1, flash2, flash3, etc). Then use Javascript to create a random number between 1 and 4 (or however many flash files you have), and assign it to a variable.
Then use something like:
var fo = new FlashObject("flash/header' + randomnumbervariable + '.swf", "animationName", "100%", "348", "8", "");
I may not have your exact syntax right, but I use somthing similar to display a random image on one of my sites.
Between your knowledge of Javascript and my knowledge of Flash, we both know nothing. However, I'll post a little more of your code, modified with the Javascript I use. It may work, or it may not:
<script type="text/javascript">
' put in the random number function
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
maximages=4; ' set this to the total number of flash images you have
function rnd() {
rnd.seed = (rnd.seed*9301+49297) % 233280;
return rnd.seed/(233280.0);
};
function rand(number) {
return Math.ceil(rnd()*number);
};
' the original code, with the next line modified for the max images
var fo = new FlashObject("flash/header' + rand(maximages) + '.swf", "animationName", "100%", "348", "8", "");
fo.addParam("allowScriptAccess", "sameDomain");
fo.addParam("quality", "high");
fo.addParam("scale", "noscale");
fo.addParam("loop", "false");
fo.write("flashcontent");
</script>
If you number your flash images as outlined in the previous message, this may work, although I don't know about the animationName variable - that's where your Flash knowledge comes in.