PDA

View Full Version : Dymanic Images Resize


icefreez
02-06-2008, 03:10 PM
I have been in my spare time trying to figure out how to load an image dynamically wait for it to load, and then determine its width. Once I have the width I want to load another one right beside it sort of like a stream of photos.
I = Image | = edge of image. Example: I|I|I|I|I|I

I have seen several tutorials on how to do this but I can never get them to work the way I want. Since the code I found was not commented :(.

Would anyone be so kind as to explain the procedure for this?

adrianTNT
02-06-2008, 08:41 PM
Here is a sample from Adobe Live docs, I placed some comments in it, maybe you understand it better.
The onloadinit is the one you need...


// create a new empty clip, place it at next available level
this.createEmptyMovieClip("image_mc", this.getNextHighestDepth());
// dfine a new listener
var loader_listener:Object = new Object();
// specify what to do when loading is completed
loader_listener.onLoadInit = function(target_mc:MovieClip) {
// you can refer to current clip as "target_mc"
trace(target_mc._width);
};
// create a "Loader"
var image_loader:MovieClipLoader = new MovieClipLoader();
// link the loader to the listener
image_loader.addListener(loader_listener);
// load the image
image_loader.loadClip("http://www.macromedia.com/images/shared/product_boxes/112x112/box_studio_112x112.jpg", image_mc);

adrianTNT
02-06-2008, 08:48 PM
This is another sample to load more images one next to another, next image will load when current one finishes loading:

function load_image(image_number, x_position) {
// create a new empty clip, place it at next available level
this.createEmptyMovieClip("image_mc"+image_number, this.getNextHighestDepth());
this["image_mc"+image_number]._x = x_position;
// dfine a new listener
var loader_listener:Object = new Object();
// specify what to do when loading is completed
loader_listener.onLoadInit = function(target_mc:MovieClip) {
// you can refer to current clip as "target_mc"
trace(target_mc._width);
// load next image and place it at 10 pixels after current one
if (image_number<5) {
load_image(image_number+1, target_mc._x+target_mc._width+10);
}
};
// create a "Loader"
var image_loader:MovieClipLoader = new MovieClipLoader();
// link the loader to the listener
image_loader.addListener(loader_listener);
// load the image
image_loader.loadClip("http://www.macromedia.com/images/shared/product_boxes/112x112/box_studio_112x112.jpg", "image_mc"+image_number);
}
// trigger loading of first image
load_image(1);


I attached the files.

icefreez
02-06-2008, 09:16 PM
Thank you so much I will take a look at this once I get home today. :D