Results 1 to 4 of 4

Thread: random & swf

  1. #1
    Join Date
    Jun 2008
    Location
    Montmagny, Québec
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy random & swf

    Hi! I need help!

    I had a code for add 2 .swf in my html. Now I want 3 .swf but my code doesn't work!! Someone wants help me please?


    ___________________________________

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

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

    {movie1();
    }

    else

    {movie2();
    }

    else

    {movie3();
    }


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

    function movie1(){
    document.write("<object classid=\'clsid27CDB6E-AE6D-11cf-96B8-444553540000\' codebase=\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width=\'855\' height=\'500\'><param name=movie value='index.swf'><param name=quality value=high><embed src='index.swf' quality=high pluginspage=\'http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\' type=\'application/x-shockwave-flash\' width=\'855\' height=\'500\'></embed></object>")
    }

    function movie2(){
    document.write("<object classid=\'clsid27CDB6E-AE6D-11cf-96B8-444553540000\' codebase=\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\' width=\'855\' height=\'500\'><param name=movie value='index2.swf'><param name=quality value=high><embed src='index2.swf' quality=high pluginspage=\'http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\' type=\'application/x-shockwave-flash\' width=\'855\' height=\'500\'></embed></object>")
    }

    function movie3(){
    document.write("<object classid=\'clsid27CDB6E-AE6D-11cf-96B8-444553540000\' codebase=\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\' width=\'855\' height=\'500\'><param name=movie value='index3.swf'><param name=quality value=high><embed src='index3.swf' quality=high pluginspage=\'http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\' type=\'application/x-shockwave-flash\' width=\'855\' height=\'500\'></embed></object>")
    }


    ___________________________________

    I can't find my error... Thx!

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Here we go, I fixed and cleaned it up for you.
    Code:
    // Generate a Random Number
    var movieDis; //global variable
    var number = 2; //your number of videos -1
    var randomnumber = Math.round(Math.random()*number+1); //generate a random number between 1-number+1
    movie(randomnumber);
    
    //Functions to write out the correct flash movie resource.
    function movie(num){
    if(num == 1){
    movieDis = "<object classid=\'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\' codebase=\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width=\'855\' height=\'500\'><param name=movie value='index.swf'><param name=quality value=high><embed src='index.swf' quality=high pluginspage=\'http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\' type=\'application/x-shockwave-flash\' width=\'855\' height=\'500\'></embed></object>";
    } else if(num == 2){
    movieDis = "<object classid=\'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\' codebase=\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\' width=\'855\' height=\'500\'><param name=movie value='index2.swf'><param name=quality value=high><embed src='index2.swf' quality=high pluginspage=\'http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\' type=\'application/x-shockwave-flash\' width=\'855\' height=\'500\'></embed></object>";
    }else if(num == 3){
    movieDis = "<object classid=\'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\' codebase=\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\' width=\'855\' height=\'500\'><param name=movie value='index3.swf'><param name=quality value=high><embed src='index3.swf' quality=high pluginspage=\'http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\' type=\'application/x-shockwave-flash\' width=\'855\' height=\'500\'></embed></object>";
    } else {
    movieDis = "There was an error. Please try again."; //error
    }
    document.write(movieDis);
    }
    When you want to add another movie, the highlighted is where you want to add another number. That indicates the number of movies -1, so for now you've got 3 mvoies, so I put it at 2, 3-1=2(if you didn't know. ). To add another movie, simply add:
    Code:
    }else if(num == x){
    movieDis = "null for now. :D";
    Before the } else {. The first highlighted is a variable x, thats the number indicating what number movie it is. And the second highlighted "null for now. " is where your gonna want to put your object.
    Also I see that if the randomnumber equals 0 in your script, it will go to movie1(same as in my script). So I think that this is gonna function right and exactly how yours does, except... Well... Without the part that it doesn't work.
    Last edited by Nile; 06-09-2008 at 12:21 AM.
    Jeremy | jfein.net

  3. #3
    Join Date
    Jun 2008
    Location
    Montmagny, Québec
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thx!!

    It's work!
    Thank you!!

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I also updated my post 5 minutes after you posted. It gives a quick tutorial. That my be useful in the future.
    I also updated the code to be a bit neater. So use the updated.
    Jeremy | jfein.net

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •