Preloading XML images

Hello all I need a little help preloading images from my xml file. I have dynamic text and dynamic images being loaded into movie clips on the stage

when I preload my xml file everything goes fine except my images hang for a while before they get loaded into there respected movieclips even when my preloader reaches 100% they are still hanging trying to load and eventually they will load.

I am able to preload my xml file by using my_xml.getBytesTotal() and my_xml.getBytesLoaded but I noticed that only includes what data is in the xml file “mainly text” and not the image paths to the actual image files. How would I go about preloading everything?

any help greatly appreaciated :slight_smile:

when you load an external image (jpg or swf) into a movie clip, you need to use the getBytesTotal()/Loaded() on the movie clip…

so if you are loading images into holder_mc then make a preloader and use

(holder_mc.getBytesLoaded()/holder_mc.getBytesTotal())*100

To matthewjumps: thanx for the reply I am a little confused because of the way I have set up my xml to load images into my movie clip "thumb_mc"
I am currently using a this.onEnterFrame to try and get the bytesTotal()/bytesLoaded () of the movie clip “thumb_mc”

here is my code
this.onEnterFrame = function() {
var loaded:Number = thumb_mc.getBytesLoaded()/thumb_mc.getBytesTotal() * 100;

loader._xscale = loaded;
}

should I be using a this.onEnterFrame? cause I was already using this.onEnterFrame to get bytesLoaded and the bytesTotal of my xml file

here is the code that I am using to load my image into thumb_mc

for (i=0; i<total; i++) {
image* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
description* = xmlNode.childNodes*.childNodes[1].firstChild.nodeValue;
date* = xmlNode.childNodes*.childNodes[2].firstChild.nodeValue;
var content_mc = update_mc.attachMovie(“Update_Container”, “Upadate_Container”+i, i);
content_mc._y = Math.floor(i/1)content_spacing;
content_mc.holder_mc.thumb_mc.loadMovie(image
);
content_mc.desc_txt.autoSize = true;
content_mc.desc_txt.text = description*;
content_mc.date_txt.text = date*;

}
};

thanx for any help :slight_smile:

use an onEnterFrame for the actual thumbs_mc…thats what id do i think…

but i cant fully understand why you have some of that code there…can you post a fla and ill fix it up for you :wink:

yeah i think i have the same problem…

I’m calling the image paths from XML and assigning them to variables in Flash with FOR like…


for (i = 0; i < total; i++) {
  this.createEmptyMovieClip("thumb" + i, i);
  this["thumb" + i].loadMovie(thumb*);
  this["thumb" + i].getBytesLoaded() == this["thumb" + i].getBytesTotal() ? DO SOMETHING : null;
}

But it doesn’t seem to work. What I had it doing was displaying a loading animation, like a black dot blinking or something like that, and then when the image was loaded, the black dot MC moved forward a frame to a button with different onPress and onRelease
properties.
AND… I tried tracing the …getBytesTotal, and no matter how I wrote it, the trace always returned 0. I’m not
sure why, as even though the trace returned 0, when I tested the movie with the simulated download, the thumbnails still lagged because they were being loaded.

So i’m stumped too…

To matthewjumps thanx for your help and reply I tried to clean up a little bit I am just starting out in flash and kind of picking up here and there through theses forms so there is probally some code in there that I dont need . Here is the link to the fla file again thanx for your help http://webpages.charter.net/theartofjae/upload.fla

ok im looking at it…

heres an intersting comment about using XML.getBytesLoaded()

“If you attempt to use this example to load a local file that resides on your hard disk, this example will not work properly because in test movie mode Flash Player loads local files in their entirety.”

To:matthewjumps I know my .fla file is kind of crazy. The code I am trying to get to work is on frame 3 inside a movie clip called “Update_Container” on frame 3 if you double click inside that and look at my actions layer you will see all the code that I am using. I know its burried deep but I thought it would give me more control over my movie clips if I worked this way instead of putting everything on the main time line hope this helps :slight_smile:

Last night I made some progress on the thumb_mc movie clip layer I added this code after searching through the fourms.


this.onEnterFrame = function(){
clipSize = thumb_mc.getBytesTotal();
loadedSize = thumb_mc.getBytesLoaded();
 if (clipSize != loadedSize) {
 
loader._xscale = 100*clipSize/loadedSize;
 
}

i replaced what I thought was correct “==” with this “!=” and it worked that really baffles me because when I write “==” it does not work.

Well I will keep trying thanx for all your help.

Status Update:

I used the following code to get it working. I thought I was supposed to use a delete this.onEnterFrame after and onEnterFrame event but when I do the preloader will not work so I just removed it.


 
this.onEnterFrame = function() {
var bytesLoaded = thumb_mc.getBytesTotal();
var bytesTotal = thumb_mc.getBytesLoaded();
var percentLoaded = bytesLoaded/bytesTotal * 100;
myloader._xscale = percentLoaded;
myText.text = Math.round(percentLoaded) + "%";
 
}