Link to home
Start Free TrialLog in
Avatar of BendOverIGotYourBack
BendOverIGotYourBack

asked on

How - Random Images in Flash Movie?

I found this article here: https://www.experts-exchange.com/questions/21208909/Random-Image-Display.html?query=random+images&topics=116


imageNum = random(10);
imageName = "image"+imageNum+".jpg";
loadMovie(imageName,_root.holder); // holder is the instance name of your movieclip target


But I have no idea how to get this to work with my test flash movie here : http://131.216.35.235/test2.htm    Source File: http://131.216.35.235/test2.fla

What I want is for the Image to be randomly selected just like the code above it tells it to do.  However, I'm new to flash mx 2004 and I don't understand how to achieve this, so I essentially need a step-by-step walkthrough (hence the 250pts).  What I would like is for Flash to pull the images (gif) from a folder in my web labeled logos.

Here's what I have in the logos folder, which is in the root of my web along w/ the flash movie.
image1.gif
image2.gif
image3.gif

If you need more information, please let me know and I'll do my best to explain further.  Thanks!!!!


Avatar of onFocus
onFocus

You can not load gif images.
imageNum = random(10);
imageName = "image"+imageNum+".jpg";
loadMovie(imageName,_root.holder); // holder is the instance name of your movieclip target

You would place the code above on the first frame of your main swf, same place as you have button1 at the moment.

If you have 3 jpegs in the same folder as your main swf will be residing, your random statement would be
imageNum = random(4);

this will return either 1,2 or 3

the next line
imageName = "image"+imageNum+".jpg";
concatenates a string, consisting of the word 'image', followed by your random number, followed by .jpg, so that the full string may read image1.jpg. If the jpeg is in the same folder as the main swf, then it will call it correctly from there. If it is in a subfolder, you need to either call it for its full path (http://mywebsite/folder1/image1.jpg) or for its relative path (folder1/inage1.jpg)

If it is in one folder from the root, and the main swf is in a folder off the root too (but a different one), then it s path would be '../folder1/image1.jpg'.
With this in mind, the line of code
imageName = "image"+imageNum+".jpg";
may need to be changed to:
imageName = "folder1/image"+imageNum+".jpg";
or
imageName = "../folder1/image"+imageNum+".jpg";
etc

On the first frame of your main swf you need to create an empty movieclip (you can do this from the library by clicking on the white folder with the plus sign on it at the bottom left of the library window, ir from the menu->insert->new symbol), and name the instance (in the properties window) 'holder'.(minus the single quotes)
This can be placed top left of where you want the top left corner of the image to be on stage, and this is where the loaded images will be loaded to.

Billystyx
... and of course onfocus is right - you can load jpegs but not gifs.

Billystyx
Avatar of BendOverIGotYourBack

ASKER

Billystyx, I'm lost at this point:
"This can be placed top left of where you want the top left corner of the image to be on stage, and this is where the loaded images will be loaded to."


When I insert an empty movie clip, a huge white space appears on my screen, which I'm assuming is the empty movie clip.  But how I position or where to add the action scrip, I do not know.  I've also changed the images to .jpeg.
ASKER CERTIFIED SOLUTION
Avatar of Billystyx
Billystyx

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well, nevermind. I figured out how to position the movie clip, I think.  See Here:http://131.216.35.235/test4.fla    or http://131.216.35.235/test4.html

However, don't see any of the images showing.  Do you know what I did wrong?

http://131.216.35.235/image1.jpg
http://131.216.35.235/image2.jpg
http://131.216.35.235/image3.jpg
Ahh, I finally got it to work locally, not sure why it's not working on my web. Many thanks Billystyx!!
Yes.

The code you placed inside the holder mc, should have been placed outside it, on the main timeline, on the first frame, same as where the holder mc was placed.

Secondly, the holder mc was not named - the instance name must be holder, not necesareily the name of the mc.

Also rename you rimages image0.jpg, image1.jpg and image2.jpg - just remembered random starts from 0 and goes up to the number before the number in your random function

so it would be this
random(3); will retrieve 0,1, and 2
anyway, try this:
http://members.lycos.co.uk/billystyx/download.htm

there is one zip file in top left called controlerv2.zip

download that - inside there are several flas, yours is test5

Billystyx