Need help loading 4 external .jpgs randomly and resize them?
Hello there,
I have quite the task in front of me. I have designed a homepage that has 4 boxes on the right hand side that are of different size. I would like to have a movie loader that loads .jpgs randomly from a specified folder into each box. At the same time I don't want any repeats in any of the 4 boxes. Also is it possible to resize the images according to the box size without having to resize them outside of flash? I can have all the images in the external folder the same size, but then if I can just shrink them with whichever image falls into the box the random script assigns.
Does that make sense?
Look at the attached .swf and .fla. That should help clarify my question.
Create a new array to store the jpg numbers you have loaded. Use the xml data to tell you how many jpgs there are. Then generate a random number between zero and the total jpgs. Check the number against the array of loaded jpgs. If not found, push the random number into the array and load the jpg.
You should use movieClipLoader because it will tell you when the jpg is visible so you can get its width and height. There's a time gap between the time when a jpg has loaded and when it's actually showing. You can't get the width and height until it's showing. Below is example of loading jpgs one after another. You can get the height and width inside the onLoadInit function so resize the jpgs there.
Code:
var mclListener:Object = new Object();
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);
var imageLoading:Number = 0;
function loadImages(){
if(imageLoading < 3){
imageLoading++;
image_mcl.loadClip("images/pic_"+imageLoading+".jpg", _root["picHolder_" + imageLoading]);
}else{
trace("loadImages(): all images have loaded");
}
}
mclListener.onLoadInit = function(target_mc:MovieClip) {
trace("onLoadInit: clip=" + target_mc);
target_mc._parent._parent.loadingAnimation._visible = false;
loadImages();
}
loadImages();
Also, don't use eval like that. Use regular object references.