# Problem in Drawing a square/rectange

**URL:** <https://forum.kirupa.com/t/problem-in-drawing-a-square-rectange/273508>\
**Category:** Uncategorized\
**Created:** [October 16, 2008, 9:54am UTC](https://forum.kirupa.com/t/problem-in-drawing-a-square-rectange/273508 "2008-10-16T09:54:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aloseous](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Aloseous](https://forum.kirupa.com/u/Aloseous)\
**Post date:** [October 16, 2008, 9:54am UTC](https://forum.kirupa.com/t/problem-in-drawing-a-square-rectange/273508/1 "2008-10-16T09:54:08Z")

</div>

Hai!!  
I have created a MovieClip using CreateMovieClip to draw a square or Rectangle. The problem is when mouse Moved it , it is creating many number of squares below it.

Here is the code which i ve tried…

var sx:Number;  
var sy:Number;  
var swid:Number;  
var **:Number;  
var mouseListener:Object = new Object();  
mouseListener.onMouseDown = function () {  
this.isDrawing = true;  
sx = Number(\_xmouse);  
sy = Number(\_ymouse);  
};  
mouseListener.onMouseMove = function () {;  
if (this.isDrawing) {;  
swid = Number(\_xmouse-sx);  
\*\*\*\* = Number(\_ymouse-sy);  
};  
updateAfterEvent();  
createbox();  
};  
function createbox() {  
this.createEmptyMovieClip(“square\_mc”,this.getNextHighestDepth());  
square\_mc.beginFill(0x0099FF,100);  
square\_mc.lineStyle(0,0x0099FF,100);  
square\_mc.moveTo(sx,sy);  
square\_mc.lineTo(sx+swid,sy);  
square\_mc.lineTo(sx+swid,sy+**);  
square\_mc.lineTo(sx,sy+\*\*\*\*);  
square\_mc.\_alpha = 50;  
square\_mc.endFill();  
updateAfterEvent();  
}  
mouseListener.onMouseUp = function () {  
this.isDrawing = flase;

};  
Mouse.addListener(mouseListener);
