Results 1 to 6 of 6

Thread: Random File

  1. #1
    Join Date
    Jul 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Random File

    I have made a code of an arcade and i want to be able to have a random game appear. How can i have ti so a random .swf file apperars with remotley hosted files?

    Thanx

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Appears where? With javascript you generally set up an array of the items to randomize, randomize the array or its counters and then use document.write to write a line or two of html containing the code to do whatever it is you normally would just have html for ex:

    HTML Code:
    <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="120" WIDTH="770" ALIGN=""> 
    <script type="text/javascript">
    
    swfFiles= new Array()
    swfFiles[0]='zap.swf'
    swfFiles[1]='golf.swf'
    swfFiles[2]='pinball.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="120" width="770"></embed>   
    </object>
    Put that on your page where normally you would have the plain call for the flash, each time the page loads, it should display a random flash from the array. You can add as many items to the array as you like. Untested (should work though) and could use work to make it degrade well for non javascript enabled browsers.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jul 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have it so there is 10 games per page. I am going to save it as a .js file. Will the code be affected any way?
    Last edited by Brian24; 07-04-2005 at 06:33 AM. Reason: Needed more info

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, if you take a look at what I've written, there are two scripts inserted inside of an object element/embed element pair which are mostly just plain HTML. If you use external .js files in place of the two scripts and you know the basics of how to do that, then there should be no problem (assuming the code works as it is now). My advice is to try it out first as written, to see if the concept works. I have some ideas on refining it but, it would be pointless to go ahead unless we get it working 'as is' first. Again, if you think you know what to do, go ahead, enjoy. You are aware that about half of what I wrote is just the plain HTML used to display a flash movie, aren't you? Only the parts that have:

    <script type="text/javascript">

    </script>

    around them are javascript. And, for all I know (I'm not real up on flash yet) you may need a different HTML syntax to call a flash game (as opposed to a movie).
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Ok, I wrote one that I know works with flash 'movies'. The first one had a few bugs. If the syntax for a game is different we can change that later. I also added code for non javascript enabled browsers. Its values need to be edited like normal HTML flash tags. In the script, some editing of the parameters (like quality or align) may be needed to suit, others may need to be added for your particular purposes. I really hope you know how to write normal flash HTML object/embed code.

    Code:
    <script type="text/javascript">
    
    swfFiles= new Array()
    //Set Flash sources, widths and heights
    swfFiles[0]=['zap.swf', 770, 120 ]
    swfFiles[1]=['golf.swf', 770, 120 ]
    swfFiles[2]=['pinball.swf', 770, 120 ]
    
    ////////////////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> 
    <noscript> <!-- Keep this tag -->
    <!-- Place Flash code for non javascript enabled browsers below -->
    <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="120" WIDTH="770" ALIGN=""> 
    <PARAM NAME="movie" VALUE="zap.swf"> 
    <PARAM NAME="quality" VALUE="high">  
    <embed src="zap.swf" 
    quality="high" 
    pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" 
    type="application/x-shockwave-flash" 
    height="120" width="770"></embed>   
    </object><!-- End non javascript Flash code -->
    </noscript><!-- Don't remove this tag -->
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Jul 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Here is the code I want to add a page to that would display a random movie/game. I tried with the codes and it problay works but you need to click on the movie/game to view it. Any way i can get that to work? This gets displayed on a FORUM!

    Code:
    <!---- Start Code for the Movie ----->
    
    <!---- Start Code for Page Links ----->
    <b>Page:</b> <a href="http://xarcade.95mb.com/loading.html" target="swf" onclick="foo('page1')">1</a>
    <a href="http://xarcade.95mb.com/loading.html" target="swf" onclick="foo('page2')">2</a>
    <a href="http://xarcade.95mb.com/loading.html" target="swf" onclick="foo('page3')">3</a>
    <a href="http://xarcade.95mb.com/loading.html" target="swf" onclick="foo('page4')">4</a>
    <!---- End Code for Page Links ----->
    
    <script src="http://xarcade.95mb.com/arcadex/arcade.js"></script>
    
    <!---- Start Code for Page Content ----->
    <div id="page1">
    <script src="http://www.bxuploader.com/userfiles/moviesx/js/page1.js">
    </script>
    </div>
    <div id="page2" style="display:none">
    <script src="http://www.bxuploader.com/userfiles/moviesx/js/page2.js">
    </script>
    </div>
    <div id="page3" style="display:none">
    <script src="http://www.bxuploader.com/userfiles/moviesx/js/page3.js">
    </script>
    </div>
    <div id="page4" style="display:none">
    <script src="http://www.bxuploader.com/userfiles/moviesx/js/page4.js">
    </script>
    </div>
    <!---- End Code for Page Content ----->
    
    <!---- Start Code for Movie Display ----->
    <div id="elemenId" style="display:none">
    <center><iframe src="http://xarcade.95mb.com/loading.html" name="swf" WIDTH=550 HEIGHT=405 scrolling="no" frameborder="0" framespacing="0" allowtransparency="true"></iframe>
    <br /><a href="http://xarcade.95mb.com/loading.html" target="swf" onclick="foo('page1')">Back to All Movies</a>
    </div>
    <!---- End Code for Movie Display ----->
    
    <!---- End Code for the Movie ----->

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
  •