FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Random picture in Flash..





borud
I'm making a webpage and I wondered if anyone knew an actionscript code that would make the page choose a random picture from a folder or something an display it. Think

Any help would be great!
Thanks=)
borud
bumping for answer...
assex
Try this out:
First put all sorts of images in different frames.
Then type this in the actions frame of frame 1:
var a = Math.random() * 10
var b = Math.ceil (a)
if (b == 1)
{
gotoAndStop (whichever frame the first image is);
}
elseif (b == 2)
{
gotoAndStop (whichever frame the second image is);
}
.....and so on

PS: I don't guarantee anything that this will work but I just wanted to try and help.
HOPE IT WORKS!
borud
Thanks Assex, I'll try that.
_VMX_
I don't know if it's too late as I've just registered to this forum, but I have a way of doing it in such a way that it picks the pictures randomly from a folder.

The only condition is, you should name the images inside your folder as 1.jpg, 2.jpg, 3.jpg... etc.

1. Create a new scene.

2. Create a new movieclip and place it where you want the images to load. After creating it, set its instace name to "container" for example.

3. Copy the whole frame (you can do it in the main timeline -> right click -> copy frames) and paste it in another frame far from the first one (the further you place it, the longer each image will be showing up).

4. Now go back to the first frame by clicking on it in the main timeline, and open up the actions panel. Write the following code:

For this example, I'll suppose the total number of images in your folder is 5, and the folder in which they are located is called "images".

Code:

folder = "images";

total = 5;

image_number = Math.floor(Math.random() * total) + 1;

image_string = String(image_number);

image_url = folder + "/" + image_string + ".jpg";

loadMovie(image_url,container);



I'll explain it by parts now, it's quite simple:

Code:

folder = "images";
total = 5;

Stores the name of the folder where the images are located in a string variable (that's why it's got the ""), and the numer of images it contains in a numerical variable (that's why it doesn't have them).

Code:

image_number = Math.floor(Math.random() * total) + 1;

Picks a random number from 1 to 5 and stores it in a numeric variable called "image_number".

Code:

image_string = String(image_number);

Converts the numeric variable to a string, which is needed to operate with it in the next step.

Code:

image_url = folder + "/" + image_string + ".jpg";

Adds the folder name, the bar (/), the image name and the ".jpg" string to compose the final URL (for example, "images/1.jpg", "images/2.jpg", etc.)

Code:

loadMovie(image_url,container);

loads the image specified in the url, into the movieclip called container, which we created earlier.


In the first frame, the movie should load a random image, and it would keep it on screen until it reaches the last frame, in which case it will return to the first frame, thus starting all over and loading a random image again which replaces the old one.

Don't hesitate in asking me any doubts you may have about it (I haven't tested this code exactly, let me know if it did).

See you Wink
Related topics
FlashCatcher-A useful software to get the flash from the web
Two Scripts that I need!
RSignatures! show the signatures in your choice!
Dynamic Signature
Eh! It's my gallery !
Random image script
need html code tht will randomly change a pic/text plz help
Dynamic Signatues (please read)
My Halo 3 Models that i have made.
my c d e drives doesnt open in a double click
I want to output an img url from a random image script
Why do so many girls pout instead of smile in pics?
This sig needs to be about 20% cooler.
finding her.........
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.