A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Help! linking to random site

  1. #1
    learning
    Join Date
    Jan 2008
    Posts
    16

    Help! linking to random site

    Ok, so i have a button, and when i click on it, I want it to got to a random site out of a few that i have supplied. This is my code now, but it doesn't work.

    Code:
    on (release) {
    	var myArray = new Array(); 
        	myArray[0] = "http://site1.swf"; 
        	myArray[1] = "http://site2.swf"; 
        	myArray[2] = "http://site3.swf"; 
    	getURL(myArray[Math.random(3)]);
    }
    + +Chuck Norris = Awesome

  2. #2
    Banned deepakflash's Avatar
    Join Date
    Aug 2007
    Location
    [Object not found]
    Posts
    1,160
    getURL(myArray[Math.floor(Math.random(3))]);

  3. #3
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Tried out the code and it didn't seem to go at random, rather it just chose the first link continuously. I found this bit of code and applied it to your situation. Seems to work for, hopefully for you as well. Cheers!
    PHP Code:
    var myArray:Array = new Array();
    myArray = ["http://site1.swf","http://site2.swf","http://site3.swf"];
    myArray.sort(function() {return Math.floor(Math.random()*3)-1});
    site myArray.pop();
    trace(myArray[Math.floor(Math.random(3))]); 
    Wile E. Coyote - "Clear as mud?"

  4. #4
    learning
    Join Date
    Jan 2008
    Posts
    16
    Thanks! that works great
    + +Chuck Norris = Awesome

  5. #5
    Banned deepakflash's Avatar
    Join Date
    Aug 2007
    Location
    [Object not found]
    Posts
    1,160
    Much simple i misplaced the "3"

    on (release) {
    var myArray = new Array();
    myArray[0] = "http://site1.swf";
    myArray[1] = "http://site2.swf";
    myArray[2] = "http://site3.swf";
    getURL(myArray[Math.floor(Math.random()*3)]);

    }

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center