Skip to main content
Participant
June 12, 2008
Question

How can I make Flash preload a bunch of jpegs?

  • June 12, 2008
  • 4 replies
  • 538 views
I want to be able to tell Flash to load about 10 external jpegs into the users cache. That way when they start clicking on the images, they come up right away. Also, could the images that are being cached be noted in an XML file?
This topic has been closed for replies.

4 replies

kglad
Community Expert
Community Expert
June 12, 2008
how you parse you xml file depends on your xml structure. if you're not using the same xml file structure as the code's author, it won't work.

p.s. use the attach code option to display code in this forum.
figure1aAuthor
Participant
June 12, 2008
I used his XML file which looks like:

kglad
Community Expert
Community Expert
June 12, 2008
delete your description line and replace your image[ i ] line with:

figure1aAuthor
Participant
June 12, 2008
So I've hijacked some of the code from:
http://www.kirupa.com/developer/mx2004/xml_flash_photogallery.htm

I've removed everything to do with the buttons, loaders, etc. from his AS and tried to just leave the code that preloads the images into the users cache. But I won't get it to preload my images in the users cache. Can anyone take a quick look at the AS below and see what I've buggered up?


function loadXML(loaded) {

if (loaded) {

xmlNode = this.firstChild;
image = [];
description = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {

image = xmlNode.childNodes.childNodes[0].firstChild.nodeValue;
description = xmlNode.childNodes.childNodes[1].firstChild.nodeValue;

}
firstImage();

} else {

content = "file not loaded!";

}

}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("images.xml");
kglad
Community Expert
Community Expert
June 12, 2008
check the xml class for help loading and parsing your xml file. but you may not be happy with the results: if a user clicks an image before it's been preloaded, it will take longer for it to load with your images loading in the background than your current setup.
kglad
Community Expert
Community Expert
June 12, 2008
execute your loadMovie() or loadMovieNum() or loadClip() methods in your main timeline's first frame.

and yes, flash can create xml files but you'll need some server-side code to save the file and that's not something i'd recommend to an actionscript novice.
figure1aAuthor
Participant
June 12, 2008
Thanks for the response. I actually don't need/want the server to create the xml files (I probably wrote that wrong above). What I want to do is have an actionscript that says "on enter frame, load the images that are in the images.xml file, but don't display them". That way when the user starts clicking on the images to display them, they'll come up nice and fast. Can someone help me write that AS?