Groups | Blog | Home
all groups > flash actionscript > july 2007 >

flash actionscript : Preloading multiple JPEGs



Tiller
7/1/2007 4:19:32 PM
I have a movie that acts as a slideshow; displaying about three images per page
with the pictures fading on and off in different positions. It sounds rubbish
but actually looks fairly good! Anyway, to keep the size of the movie down I've
used external images but really they need to be preloaded to make everything
more fluid.

Ideally the movie would start after loading the first three pictures with the
others being loaded in the background. They're not particularly big (about 10k
each) but the spilt second they do take to appear isn't ideal.

My question, therefore, is how to preload these images and then display them
in each movie clip frame when required.

As with a lot of things in Flash (and purely though my lack of technical
knowledge) it seems to be an extremely difficult process and I've found a few
tutorials on the Internet that offer similar systems but none that fit the bill
exactly.

Thanks!
GWD
7/1/2007 4:55:39 PM
I've been working on this class (as2) based on David Stiller's original work on
a MultiLoader (the link to it is in the page). It's not fully featured yet as I
am adding additional functionality for error-handling and more detailed loading
metrics. But it should allow you to do what you want. I'll provide an example
later on. I can't do it now, sorry.

http://gregdove.web.googlepages.com/multiloaderclass-wip
GWD
7/1/2007 7:47:29 PM
Here's an example using the class above, just using some images from a google
search.

When the 3rd image in the original sequence is loaded you will see the message
[b]the first 3 images have fully loaded[/b] in the output window.

You can also change the line
myImagesLoader.loadClips(3); //this limits simultaneous loading to 3
to
myImagesLoader.loadClips(1); //this limits simultaneous loading to 1 to force
sequential loading

Like I said its not completely finished but I believe its functional for what
you want/need. I'll post updates when I give it more attention to finish the
other features outlined in the comments.

import MultiLoader;
//quick google search for sample images
var images = [

"http://docs.gimp.org/images/filters/examples/color-taj-sample-colorize.jpg",
"http://admin.hotkeys.com/template_images/1187693917/sample1.jpg",

"http://toxics.usgs.gov/photo_gallery/photos/pesticides/HerbReconn/hr_grab_sampl
e_lg.jpg",

"http://www.isis.rl.ac.uk/UserSupport/images/tosca%20sample%20changer%20illustra
tion.jpg",
"http://ael.gsfc.nasa.gov/images/mars/sampleFlow.jpg",

"http://img.alibaba.com/photo/50461044/Lamp_House_for_Checking_Color_Sample_Use.
jpg",

"http://www.physics.purdue.edu/primelab/ion_source/rabbit_sample_changer/images/
tn/D2198_Sample_receiver_section.jpg"
]


var myImagesLoader:MultiLoader = new MultiLoader();

var myImageLoadListener:Object = new Object();
var myMultiLoaderListener:Object = new Object();

myImageLoadListener.onLoadInit = function(target_mc) {

trace('onLoadInit has occurred for '+target_mc);

}

myMultiLoaderListener.groupProgress = function(evtObj) {

trace('groupProgress has occurred :');
for (var detail in evtObj) trace(detail+"="+evtObj[detail]);

if (evtObj.queueProgress==3){
trace('the first 3 images have fully loaded')
//the others will continue to load, but you could start something now
}
}
myMultiLoaderListener.groupComplete = function(evtObj) {
trace('groupComplete has occurred :');
for (var detail in evtObj) trace(detail+"="+evtObj[detail]);

}
myImagesLoader.addEventListener("groupProgress",myMultiLoaderListener);
myImagesLoader.addEventListener("groupComplete",myMultiLoaderListener);

var holderClip =
this.createEmptyMovieClip("imagesHolder",this.getNextHighestDepth())
for (var i=0;i<images.length;i++) {
var newImageClip =
holderClip.createEmptyMovieClip("image"+i,holderClip.getNextHighestDepth())

//add the clip to the MultiLoader, with its listener for the onLoadInit event
myImagesLoader.addClip(images[i],newImageClip,myImageLoadListener)

}

myImagesLoader.loadClips(3); //this limits simultaneous loading to 3
Tiller
7/2/2007 2:24:45 PM
Thank you very much for your help - I'll try that a bit later and get back to you.

Cheers,

AddThis Social Bookmark Button