Looping the Drawing API

I am using the drawing API to create 2 red rectangles. The following loop should create 2 rectangles in movieclips (holder2, holder1). However, later in the timeline when I hide one of the movieclips nothing happens. I think the problem is using this.attribute to draw these rectangles. How can i get round this? Any ideas? All help appreciated…


for (var i:Number = 2; i > 0; i--) {
_root.createEmptyMovieClip("holder" + i, i);

this.lineStyle(1,0,100);
this.beginFill(0xFF0000,50);

this.moveTo(n,n)
this.lineTo(n+w,n)
this.lineTo(w,n-h)
this.lineTo(n,-h)
this.lineTo(n,n)
this.endFill(); 
}