Problem with preloader

Hello, fellow flash addicts! :beer:

Please, have a look at this code:


total = 0;
carregado = 0;
perc = 0;
loading._visible = false;
loading.onEnterFrame = function(){
    this._visible = true;
    carregado = img.getBytesLoaded();
    total = img.getBytesTotal();
    perc = Math.round(carregado / total * 100);
    this.loading._xscale = perc;
    if (carregado == total){
        this._visible = false;
        delete this.onEnterFrame;
    }
}

Seems like everything`s right, dont you agree? The problem is that, when I do “Simulate download” in Flash, the movieclip loading simply disappears! I did a few traces, and it seems that, when the movies loads, for a brief milisecond, the condition “carregado == total” is true, and that really screws the all thing. So, any of you guys could help me?

Thanks a lot!