SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Aug 2000
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Random Flash with PHP

    I hope someone can help with this.

    I have created 3 different flash files for my home page and I would like a random one displayed when a visitor comes to the site so that the site looks "fresh". I have looked at hotscripts.com and they have a couple of php scripts that will take a random file from a directory but they seem too complicated for something like this.

    Any help with the coding for this would be greatly appreciated.

    thank you

  2. #2
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, you could store the url and a id to the flash file in a database, and use a random generator to pic out a random id for the flash file.
    then print the resulting id, and use it to randomize the embed statment.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  3. #3
    SitePoint Addict
    Join Date
    Aug 2000
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I appreciate the reply but I am a complete newbie to php coming over from ASP so a little example of the sintax would help.

    Thanks

  4. #4
    SitePoint Enthusiast geeOff's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta, GA 30328
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    something simple like this should get it...using mt_rand(), $randval will just be a number between 1 and 3...and it just gets tacked onto the end of your flash file (flash_movie{number}.swf) name within the object tag. so anytime the page is loaded, flash_movie1.swf, flash_movie2.swf or flash_movie3.swf will load...everything should be peachy as long as all the movies are the same size, otherwise you will have to do some if / thens or a small function to write the different parameters for the object & embed tags.

    Geoff

    PHP Code:
    <?php
    // seed the random number generator 
    mt_srand ((float) microtime() * 1000000); 
    // generate a random number 
    $randval mt_rand(13);
    ?>
    <html>
    <head>
    <title>index</title>
    <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor=#FFFFFF>
    <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"
     WIDTH=620 HEIGHT=426>
     <PARAM NAME=movie VALUE="flash_movie<?php echo $randval ?>.swf"> 
     <PARAM NAME=quality VALUE=high> 
     <PARAM NAME=bgcolor VALUE=#FFFFFF> 
     <EMBED src="flash_movie<?php echo $randval ?>.swf" quality=high bgcolor=#FFFFFF 
    WIDTH=620 HEIGHT=426 TYPE="application/x-shockwave-flash"
     PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>
    </OBJECT>
    </body>
    </html>


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
  •