PDA

View Full Version : Random Flash Script Need Help.



todditami
01-08-2006, 07:03 AM
Hi Everyone. I can not for the life of me figure out what is wrong with this script. It has some sort of bug that it comes up blank sometimes. Can anyone help me fix it and or give me a new script? I am just simply trying to create a random flash movie that plays every time you load the page.

Here is a URL of the loaded page, just refresh it a few times and it will go blank on ya... DOh....

http://www.isu.edu/asisu/test/randomtest.shtml

Here is the script:

<script type="text/javascript">

swfFiles= new Array()
//Set Flash sources, widths and heights
swfFiles[0]=['turn.swf', 539, 200 ]
swfFiles[1]=['turn2.swf', 539, 200 ]
swfFiles[2]=['turn3.swf', 539, 200 ]
swfFiles[4]=['turn4.swf', 539, 200 ]
swfFiles[5]=['turn5.swf', 539, 200 ]
swfFiles[6]=['turn6.swf', 539, 200 ]

////////////////No Need to Edit Below Here//////////////

//Randomizing Unit Courtesy of Mike Winter as seen at:
//http://www.dynamicdrive.com/forums/showthread.php?p=8442
function random(n) {
return Math.floor((Math.random() % 1) * n);
}

Array.prototype.shuffle = function() {var i = this.length;
while(i--) {this.swap(i, random(i + 1));}
};
Array.prototype.swap = function(x, y) {
var t = this[x]; this[x] = this[y]; this[y] = t;
};

swfFiles.shuffle()
//End Randomizing Unit


document.write('\
<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" \
CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" \
HEIGHT="'+swfFiles[0][2]+'" WIDTH="'+swfFiles[0][1]+'" ALIGN=""> \
<PARAM NAME="movie" VALUE="'+swfFiles[0][0]+'"> \
<PARAM NAME="quality" VALUE="high"> \
<embed src="'+swfFiles[0][0]+'" \
quality="high" \
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" \
type="application/x-shockwave-flash" \
height="'+swfFiles[0][2]+'" width="'+swfFiles[0][1]+'"></embed> \
</object>\
')
</script>

jscheuer1
01-08-2006, 07:45 AM
swfFiles= new Array()
//Set Flash sources, widths and heights
swfFiles[0]=['turn.swf', 539, 200 ]
swfFiles[1]=['turn2.swf', 539, 200 ]
swfFiles[2]=['turn3.swf', 539, 200 ]
swfFiles[4]=['turn4.swf', 539, 200 ]
swfFiles[5]=['turn5.swf', 539, 200 ]
swfFiles[6]=['turn6.swf', 539, 200 ]

You are missing a "swfFiles[3]". Without that, in this type of situation, one is assumed but, one with no values assigned. When that one gets selected by the randomizing unit, that is probably the cause of the problem.