|
-
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
-
Banned
getURL(myArray[Math.floor(Math.random(3))]);
-
Senior Member
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?"
-
 +  +Chuck Norris = Awesome
-
Banned
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|