Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

preload 10 jpgs 1

Status
Not open for further replies.

Bignewbie

Programmer
Feb 22, 2001
351
PH
Hi guys,

I need help. I have 10 MC named "preloadMov1" to "preloadMov10" on the root of my swf. I have to preload 10 jpgs in those MCs. Any idea on how to do this?

Please help!


biggie

The Man of Tomorrow is forged by his battles today.
 
This will load the jpgs into the clips (code on the main timeline):

Code:
for(var i=1;i<=10;i++){
this['preloadMov'+i].loadMovie('images/jpg'+i);
}

If you want a real 'preload' effect you could have the clips offstage as the images load in and bring them on stage as you need them.

To get real control over the images regarding placement and sizing it's best to load them in to 'holder' clips (loading directly into a clip as above will wipe everything else in the mc). A holder clip has a second empty clip nested inside it that holds the image as it's loaded in and then you can script the 'parent' clip more easily, and maybe have other graphic elements like a border etc. I usually add an empty clip called 'loadPoint' so I know where I am:

Code:
for(var i=1;i<=10;i++){
this['preloadMov'+i].loadPoint.loadMovie('images/jpg'+i);
}

 
wangbar,

Code:
for(var i=1;i<=10;i++){
this['preloadMov'+i].loadMovie('images/jpg'+i);
}

the above code worked wonderfully, and your loadPoint idea is great! I worked out real fine, and i really didn't have much trouble about resizing it.

Another question, is there any way to know if the jpgs are done loading? it's like this: I show all 10 (thumbnail size, hence the resizing), then I show them one by one, in their original sizes, my question is, is there any way to know if all jpgs have been shown in the first part? I need some trigger for the second part where i show them one at a time.

biggie


The Man of Tomorrow is forged by his battles today.
 
You can use getBytesLoaded() and getBytesTotal() for jpgs exactly as you can for normal .swf movies so it's basically like any other preloader. So you could either cycle through each clip like this:

Code:
checkAllLoaded = function () {
//checks through each clip to see what its status is
	for (var i = 1; i<=10; i++) {
		clip = this['preloadMov'+i];
		if (clip.getBytesLoaded()<clip.getBytesTotal()) {
			return false;
		}
	}
	return true;
};
//
this.onEnterFrame = function() {
//see if everything has loaded, keep looping if it hasn't
	loadedOk = checkAllLoaded();
	if (loadedOk) {
		this.onEnterFrame = null;
		//go and do rest of movie
	}
};

...or attach an enterFrame event to each clip as it loads. I haven't checked this code actually running but it should work okay.
 
wangbar,

Thanks for the code. I'll post again if i need more help. This looks ok. thanks again! You saved my neck!


biggie

The Man of Tomorrow is forged by his battles today.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top