# Simple XML preload problem

**URL:** <https://forum.kirupa.com/t/simple-xml-preload-problem/186898>\
**Category:** flash\
**Created:** [April 25, 2006, 9:45am UTC](https://forum.kirupa.com/t/simple-xml-preload-problem/186898 "2006-04-25T09:45:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pomme\_](https://avatars.discourse-cdn.com/v4/letter/p/f14d63/32.png) [@Pomme\_](https://forum.kirupa.com/u/Pomme_)\
**Post date:** [April 25, 2006, 9:45am UTC](https://forum.kirupa.com/t/simple-xml-preload-problem/186898/1 "2006-04-25T09:45:41Z")

</div>

Hello guys, long time no see…

```auto
function chargeXML() {
    joueurs_xml = new XML();
    loader = new LoadVars();
    joueurs_xml.ignoreWhite = true;
    joueurs_xml.onLoad = function(success) {
        if (success) {
            trace("xml loaded successfully.");
            root = joueurs_xml.firstChild;
            initJoueurs();
        } else {
            trace("xml failed to load.");
        }
    };
    joueurs_xml.load("http://url.xml"); //fake xml address, can't put functionnal addy.
    _root.onEnterFrame = function() {
        preload = joueurs_xml.getBytesLoaded();
        total = joueurs_xml.getBytesTotal();
        percent = (preload/total)*100;
        trace(total);
        trace(percent);
        if (percent>=100) {
            delete _root.onEnterFrame;
        }
    };
}
chargeXML();

```

I get “undefined” for my var total and thus NaN for percent. What’s going on???

---

<div class="post-metadata">

**Author:** ![Mirandir](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Mirandir](https://forum.kirupa.com/u/Mirandir)\
**Post date:** [April 25, 2006, 12:51pm UTC](https://forum.kirupa.com/t/simple-xml-preload-problem/186898/2 "2006-04-25T12:51:24Z")

</div>

The first time onEnterFrame runs getBytesTotal() will return undefined. I’m not sure. But I think it has something to do with when Flash actually runs a load it has been told to do.

So you would need to add a check if getBytesTotal returns undefined percent is set to 0.

```auto

function chargeXML() {
... [cut] ...
        _root.onEnterFrame = function() {
        preload = joueurs_xml.getBytesLoaded();
        total = joueurs_xml.getBytesTotal();
        if(total == undefined) 
        {
                total = 0;
                percent = 0;
        } else
                percent = (preload/total)*100;
        trace(total);
        trace(percent);
        if (percent>=100) {
            delete _root.onEnterFrame;
        }
    };
}

```

/Mirandir

---

<div class="post-metadata">

**Author:** ![Pomme\_](https://avatars.discourse-cdn.com/v4/letter/p/f14d63/32.png) [@Pomme\_](https://forum.kirupa.com/u/Pomme_)\
**Post date:** [April 25, 2006, 2:20pm UTC](https://forum.kirupa.com/t/simple-xml-preload-problem/186898/3 "2006-04-25T14:20:48Z")

</div>

Thanks Mir, but it doesn’t work…  
When I trace the loading, i get :

> 

total 0  
percent 0  
total 0  
percent 0  
total 0  
…  
percent 0  
total 0  
percent 0  
total 0  
percent 0  
total 0  
percent 0  
xml loaded successfully.  
total 37153  
percent 100

As though it doesn’t see the XML until loaded, and then gives me the right size and percent…

What the hell’s gone wrong??
