Help with creating dynamic images inside a scroll bar referring to kirupa's tutorial

I have read through the tutorial posted here on creating a scroll bar in flash: http://www.kirupa.com/developer/flash8/scrollbar.htm

It worked great, when the content in the contentMain movieclip was static. However I am using this scroll bar application to create a variable amount of images in content main. So I started off with something simple, and put this actionscript code in the contentMain movie clip its self:

var regName:String = “watermark”;
var mcName = “watermark”;
var corner1:Number = 0;
var myHeight:Number = 0;
var colorVal:Number;
var xPos:Number = 100;
var yPos:Number = 30;
_global.totalContentHeight = 0;
for(var i = 0; i < 30; i++){
mcName = regName + i;
this.attachMovie(“watermark”, mcName,700+i);
eval(mcName)._x = xPos;
eval(mcName)._y = yPos;
xPos = xPos + 200;
trace(xPos);
if(xPos > 800){
yPos = yPos +200;
xPos = 100;
tempyPos = 0;
}
}
note: The image inside the watermark clip will be dynamic, however the width and height of that image is static.

Inside the watermark movieclip’s action pannel is this code:
this.lineStyle(1,0,100);
this.beginFill(0x00FF00,100);
this.moveTo(0,0)
this.lineTo(0,160);
this.lineTo(160,160);
this.lineTo(160,0);
this.endFill();

to draw a simple box.

Now the problem is that the height of contentMain is thrown way off from all of this. If I do a contentMain._hieght I get a value of 0, even after calling the scrolling function after attaching all the watermark movieclips.

So I keep track of the total height of contentMain after the movie clips are attached, and use that global variable instead of contentMain._height in the scrolling function. What results is a scroll bar that is functional, but a variable amount of white space resulting after the images are done being displayed (of about 3 times the running tally of the contentMain height in theory).

This is all based off the assumption that in theory, the height of contentMain, should be the height of all the MovieClip’s attached to contentMain, + their padding between them.

If the movieclips being attached are drawing a 160x160 square starting at 0,0; then their height should be 160 as well. So pad them by 40 pixels (yPos = yPos + 200) and yPos + 200 should be the total height of contentMain after attachign the movieclips.

contentMain lies at position 0,0 on the masked layer for the scroller, and when it’s y value is equal to the total height tracked above (the negative value of it) minus the masked height, but that is definetly not right. Anyone have any ideas as to why this is happening?