View Full Version : Load Random Pictures....
RicardoSousa
11-22-2005, 04:45 PM
I people. my englsih are terrible. i will try explain my problem!
is my 1 time post a proble in network, please help me!
i wish know if is possible when i enter in a swf file appears diferents pictures!
for example: 1 time appears the picture A, 2 time appears the picture B, 3 time appears the picture C, etc....
Can you help me!!
Paerez
11-22-2005, 08:37 PM
For loading a picture:
MovieClip.loadMovie("picture.jpg")
For random:
Math.random();
So, if you have pictures:
var arr = new Array();
arr[0] = "picture1.jpg";
arr[1] = "picture55.jpg";
arr[2] = "cat.jpg";
var showRandom = function() {
var rand = Math.floor(Math.random()*arr.length);
_root.loadMovie(arr[rand]);
}
Good Luck
Paerez
11-23-2005, 01:22 AM
If you want an example, try to do it, then post an FLA and I will fix it.
RicardoSousa
11-24-2005, 01:34 PM
I again!
its possible put several images in flash and program the flash to choose and image!
the images are put in flash file!!! no out of flash file...
its possible?
thanks :)
RicardoSousa
11-24-2005, 01:52 PM
Who i can put flash choose random images from library ?
thanks.... :)
RicardoSousa
11-24-2005, 01:53 PM
Who i can put flash choose random images from library ?
thanks....
CyanBlue
11-24-2005, 02:01 PM
Howdy and Welcome... :)
You need to use attachMovie() instead of the loadMovie() function...
(Just modifying Paerez' script...)
var arr = new Array();
// picture1 ~ 3 are the linkage identifiers set in the library for each images...
arr[0] = "picture1";
arr[1] = "picture2";
arr[2] = "picture3";
//
var showRandom = function()
{
var rand = Math.floor(Math.random()*arr.length);
// I am assuming that you have an empty movieClip on the stage
_root.holder_mc.attachMovie(arr[rand], "random_mc", 100);
}
//
showRandom();
RicardoSousa
11-24-2005, 04:30 PM
its possible put flash choose random images from library?
thanks for helping....
not without having an array with the name of all the images or something similiar
ashenarya
11-24-2005, 04:43 PM
well, you could linkage your images with a number so when you want to attach ne, just throw a random.
aamenabar
11-25-2005, 01:14 AM
Hi. (this is my first reply ever :p)
there is no need for an array, I've done it, not that hard...
let's say you have 5 images
put each one of them in a MovieClip named in order, like this:
img1
img2
img3
img4
img5
BUT, (here is the first trick) In the convert to symbol window, in advanced mode, you must check the "Export for Actionscript" check box, then, the linkage group will become active and it will propose a name for attaching the MovieClip (MC for short). Here is where it's important to write the names in secuence.
Now, for practical matters, you must put an empty MC in the stage, (don't use code, this way is easier to visualize where is the image going to load). Then put an intstance name to it, in this case we'll use "cont"
Now the code:
In the main timeline, in the frame where you want te images to apear, put the following code:
_root.cont.attachMovie("img"+(random(5)+1),hola,1);
what the above code does I'll explain for parts:
- _root.cont. (is the path of the object where the MCs are going to load in)
- attachMovie (is the command to load a MC from the lybrary)
- "img" (is the part in common of all the MCs names)
- + (the plus sign adds an expresion or calculation if you want to the sting "img")
- random (5) (is a function that will return a number between 0 and 5, "0" included, "5" not included)
- +1 (is for the case when the random function returns 0 and you want 1 or 4 and you want 5, or you could just ignore this and name your MCs starting from "0" ) :D
- ,hola (is just the instance name I chose to give the attached MovieClip)
- ,1 ( is the level where it will be attached inside the "cont" MC)
Hope this helps:rolleyes:
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.