Path problem in loop

I have three movie clips on stage that I want to fill with dynamically loaded jpegs and then resize jpegs so they fit the movie clips.

This is what I came up with:


var maxWidth = 150;
var maxHeight = 100;
var i:Number;
for (i = 1; i < 4; i++) {
    var container = "button"+i+".emptyMC"
    var thumbloader = new MovieClipLoader();
    thumbloader.loadClip("img"+i+".jpg",container);
    thumbloader.onLoadInit = function(ctnr:MovieClip, i:Number) {
        trace([COLOR=Black]container[/COLOR]);
        if ([COLOR=DarkRed]container[/COLOR]._width>=200) {
            var ctnrWidth = [COLOR=DarkRed]container[/COLOR]._width;
            scalePercent = (ctnrWidth>maxWidth) ? maxWidth*100/ctnrWidth : scalePercent;
            [COLOR=DarkRed]container[/COLOR]._xscale = scalePercent;
        }
        if ([COLOR=DarkRed]container[/COLOR]._height>=100) {
            var ctnrHeight = [COLOR=DarkRed]container[/COLOR]._height;
            scalePercent = (ctnrHeight>maxHeight) ? maxHeight*100/ctnrHeight : scalePercent;
            [COLOR=DarkRed]container[/COLOR]._yscale = scalePercent;
        }
    };
}

It attaches pictures like it should only the resizing part doesnt work. The value of container is stuck with “button3.emptyMC” and the only way I can get this code to work is if I change everything that is in red with actual path (button1.emptyMC).

What am I doing wrong?

Thanks