Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 422
  • Last Modified:

How - Random Images in Flash Movie?

I found this article here: http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q_21208909.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!!!!


0
BendOverIGotYourBack
Asked:
BendOverIGotYourBack
  • 4
  • 3
1 Solution
 
onFocusCommented:
You can not load gif images.
0
 
BillystyxCommented:
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
0
 
BillystyxCommented:
... and of course onfocus is right - you can load jpegs but not gifs.

Billystyx
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
BendOverIGotYourBackAuthor Commented:
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.
0
 
BillystyxCommented:
OK, when you insert an empty mc it opens it automatically for editing. Just click on the 'Scene1' tab at the top of the window to take you back to the main timeline, and then you will see the empty mc as a white dot on screen. If its not onscreen for any reason, drag it from the library (will probably be called symbol1), and then you will see it.
The position of the white dot will be the top left of your jpegs as they load.
You must name it (from the maintimeline, or Scene1 as it is called),'holder', for it to load the jpegs.
In the bottom left of screen, there will be either open or closed a window called properties and you can name it in there, in the white box named 'instance'

Billystyx
0
 
BendOverIGotYourBackAuthor Commented:
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
0
 
BendOverIGotYourBackAuthor Commented:
Ahh, I finally got it to work locally, not sure why it's not working on my web. Many thanks Billystyx!!
0
 
BillystyxCommented:
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
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now