Hello.
I have a little problem. I want to know how to make random URL:s in Flash. Or load an movie randomly.
thanks
/plankan
Hello.
I have a little problem. I want to know how to make random URL:s in Flash. Or load an movie randomly.
thanks
/plankan
You have to use arrays!
yourarray = ["URL1", "URL2", "URL3", "ULR4"] //list all the URLs you want to choose from!
now if you want to go to a new url with a click on a button then use this code to choose a random one from them when a button is clicked!
on(release) {
getURL(yourarray[Math.round(Math.random()*yourarray.length)]);
}
or if you want to load a new random movie then list the movies in an array like the URLs and use this piece of code to load a random one!
on(release) {
loadMovie(yourarray[Math.round(Math.random()*yourarray.length)], 0)
}
what this line : getURL(yourarray[Math.round(Math.random()*yourarray.length)]);
does is:
Math.random <-- picks a random number between 0 and the lentgh of the array (note that the members in the array are counted “0, 1, 2, 3, etc.” NOT “1, 2, 3, 4, etc”!)
Math.round <-- rounds the random number to a good number like “9” or “2” not “9.93985743”!
now if you would like to pick for example the fourth member in the array then you should use the code like this:
getURL(yourarray[4]);
and to load movie you have to load it onto/into (whatever) a movieclip like
_root.mymc.loadMovie
then the movieclip “mymc” will be replaced with the contents of the loaded movie!
Cheers!
Thanks for the help. It worked.
Now i wounder if i can make it so it both load an movie an make a “goto” in the same press? Is that impossible?
Thanks
/plankan
Then you would have to use 2 arrays, one for loadmovie and one for getURL! For example array1, array2 or sth!
just make 2 arrays with different names (current name “yourarray”)
and use both actions, getURL and loadMovie, for the button like this:
on(release) {
getURL(blablabla);
_root.something(blablabla);
}
:: Copyright KIRUPA 2024 //--