# Preloading XML images

**URL:** <https://forum.kirupa.com/t/preloading-xml-images/182607>\
**Category:** Uncategorized\
**Created:** [March 20, 2006, 12:40am UTC](https://forum.kirupa.com/t/preloading-xml-images/182607 "2006-03-20T00:40:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kansai](https://avatars.discourse-cdn.com/v4/letter/k/cdc98d/32.png) [@kansai](https://forum.kirupa.com/u/kansai)\
**Post date:** [March 20, 2006, 12:40am UTC](https://forum.kirupa.com/t/preloading-xml-images/182607/1 "2006-03-20T00:40:23Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![matthewjumps](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matthewjumps](https://forum.kirupa.com/u/matthewjumps)\
**Post date:** [March 20, 2006, 1:25am UTC](https://forum.kirupa.com/t/preloading-xml-images/182607/2 "2006-03-20T01:25:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kansai](https://avatars.discourse-cdn.com/v4/letter/k/cdc98d/32.png) [@kansai](https://forum.kirupa.com/u/kansai)\
**Post date:** [March 20, 2006, 5:22am UTC](https://forum.kirupa.com/t/preloading-xml-images/182607/3 "2006-03-20T05:22:53Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![matthewjumps](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matthewjumps](https://forum.kirupa.com/u/matthewjumps)\
**Post date:** [March 20, 2006, 5:29am UTC](https://forum.kirupa.com/t/preloading-xml-images/182607/4 "2006-03-20T05:29:32Z")

</div>

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 😉

---

<div class="post-metadata">

**Author:** ![stereochris](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@stereochris](https://forum.kirupa.com/u/stereochris)\
**Post date:** [March 20, 2006, 6:04am UTC](https://forum.kirupa.com/t/preloading-xml-images/182607/5 "2006-03-20T06:04:02Z")

</div>

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…

```auto

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…

---

<div class="post-metadata">

**Author:** ![kansai](https://avatars.discourse-cdn.com/v4/letter/k/cdc98d/32.png) [@kansai](https://forum.kirupa.com/u/kansai)\
**Post date:** [March 20, 2006, 6:09am UTC](https://forum.kirupa.com/t/preloading-xml-images/182607/6 "2006-03-20T06:09:39Z")

</div>

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](http://webpages.charter.net/theartofjae/upload.fla)

---

<div class="post-metadata">

**Author:** ![matthewjumps](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matthewjumps](https://forum.kirupa.com/u/matthewjumps)\
**Post date:** [March 20, 2006, 6:20am UTC](https://forum.kirupa.com/t/preloading-xml-images/182607/7 "2006-03-20T06:20:45Z")

</div>

ok im looking at it…

---

<div class="post-metadata">

**Author:** ![matthewjumps](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matthewjumps](https://forum.kirupa.com/u/matthewjumps)\
**Post date:** [March 20, 2006, 6:23am UTC](https://forum.kirupa.com/t/preloading-xml-images/182607/8 "2006-03-20T06:23:50Z")

</div>

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.”

---

<div class="post-metadata">

**Author:** ![kansai](https://avatars.discourse-cdn.com/v4/letter/k/cdc98d/32.png) [@kansai](https://forum.kirupa.com/u/kansai)\
**Post date:** [March 20, 2006, 5:09pm UTC](https://forum.kirupa.com/t/preloading-xml-images/182607/9 "2006-03-20T17:09:48Z")

</div>

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 🙂

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

```auto

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.

```auto

 
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) + "%";
 
}

```
