# Looping the Drawing API

**URL:** <https://forum.kirupa.com/t/looping-the-drawing-api/206950>\
**Category:** flash\
**Created:** [November 13, 2006, 1:45pm UTC](https://forum.kirupa.com/t/looping-the-drawing-api/206950 "2006-11-13T13:45:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve\_b](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@steve\_b](https://forum.kirupa.com/u/steve_b)\
**Post date:** [November 13, 2006, 1:45pm UTC](https://forum.kirupa.com/t/looping-the-drawing-api/206950/1 "2006-11-13T13:45:37Z")

</div>

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…

```auto

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(); 
}

```
