# Only first drawn rectangle is dragged all the time

**URL:** <https://forum.kirupa.com/t/only-first-drawn-rectangle-is-dragged-all-the-time/190892>\
**Category:** flash\
**Created:** [June 15, 2006, 1:39pm UTC](https://forum.kirupa.com/t/only-first-drawn-rectangle-is-dragged-all-the-time/190892 "2006-06-15T13:39:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nish](https://avatars.discourse-cdn.com/v4/letter/n/9dc877/32.png) [@nish](https://forum.kirupa.com/u/nish)\
**Post date:** [June 15, 2006, 1:39pm UTC](https://forum.kirupa.com/t/only-first-drawn-rectangle-is-dragged-all-the-time/190892/1 "2006-06-15T13:39:32Z")

</div>

## Dear all, The code below is used to create one rectangle at a time when a button pressed. But they are randomly placed on the screen. I was trying to drag each and place each rectangle in a desired location on screen. ![](http://forum.kirupa.com/uploads/kirupa/755/062222e6fedaef86.gif) But when I drag a rectangle (startDrag) with MouseDown ONLY THE FIRST CREATED RECTANGLE IS MOVED AND NOT OTHER RECTANGLES. Can you throw some light on it please?

var i = 0  
function newRectangle(x1,y1){

var r:MovieClip = this.createEmptyMovieClip(“rectangles”+i, (i+2));  
r.beginFill(0xcc00cc, 100);  
r.moveTo(20, 20);  
r.lineTo(140, 20);  
r.lineTo(140, 80);  
r.lineTo(20, 80);

r.endFill();  
r.\_x = x1  
r.\_y = y1

i++  
r.createTextField(“txt”,2,25,25,10,10)  
r.txt.text = "Statement " + i  
r.txt.autoSize = true  
r.\_alpha = 100;  
r.onMouseDown= function(){  
startDrag(this);}  
r.onMouseUp = function() {  
stopDrag();}  
}
