?
Solved

How - Random Images in Flash Movie?

Posted on 2005-03-12
8
Medium Priority
?
417 Views
Last Modified: 2008-02-01
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
Comment
Question by:BendOverIGotYourBack
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 4

Expert Comment

by:onFocus
ID: 13525766
You can not load gif images.
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13525785
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
 
LVL 18

Expert Comment

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

Billystyx
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:BendOverIGotYourBack
ID: 13526390
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
 
LVL 18

Accepted Solution

by:
Billystyx earned 1000 total points
ID: 13526439
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
 

Author Comment

by:BendOverIGotYourBack
ID: 13526460
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
 

Author Comment

by:BendOverIGotYourBack
ID: 13526486
Ahh, I finally got it to work locally, not sure why it's not working on my web. Many thanks Billystyx!!
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13526508
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question