Random Flash movie embedding

Discussion in 'Web Design and Development' started by The Friz, Dec 27, 2007.

  1. The Friz macrumors newbie

    Joined:
    Oct 25, 2007
    #1
    Having some trouble trying to get a page to show a different swf every time the page is loaded/refreshed. I have some .js written (right now its only 3 movies, but ideally 20+). It's actually the only thing on the page so it should be easy.....

    Here's the .js:

    <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="700" WIDTH="525" ALIGN="">
    <script type="text/javascript">

    swfFiles= new Array()
    swfFiles[0]='movie1.swf'
    swfFiles[1]='movie2.swf'
    swfFiles[2]='movie3.swf'

    //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;
    };
    //End Randomizing Unit

    swfFiles.shuffle()

    document.write('<param name="movie" value="'+swfFiles[0]+'">'
    </script>
    <PARAM NAME="quality" VALUE="high">

    <script type="text/javascript">
    document.write('<embed src="'+swfFiles[0]+'"')
    </script>
    quality="high"
    pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"
    type="application/x-shockwave-flash"
    height="700" width="525"></embed>
    </object>

    and the html to link to it:

    <html><body leftmargin=0 topmargin=0><param name="movie" value="trivia.js"><embed src="trivia.js" width="700" height="525"></embed></object><html>

    Ive tried a few different methods with no success. Any help would be greatly appreciated! Thanks
     
  2. iSee macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #2
    One error is that you have a syntax error in your Javascript at the end of the first javascript block:

    Code:
    document.write('<param name="movie" value="'+swfFiles[0]+'">'
    is missing the closing paran. I'm not sure if this is what's causing your problem though.
     

Share This Page